求区间a到b(正整数)之间约数个数最多的数,并输出他的约数。

约数是能整除x的正整数。

 1 #include<stdio.h>
 2 #include<stdafx.h>
 3 #include<iostream>
 4 #include<string>
 5 using namespace std;
 6 
 7 int div(int a)
 8 {
 9     int count,i,k;
10         count=0;
11     for(i=1;i<=a;i++){
12         k=a%i;
13         if(k==0)
14             count++;
15     }
16     return count;
17 }
18 
19 int main(){
20     freopen("D://input.txt","r",stdin);
21     freopen("D://output.txt","w",stdout);
22 
23     int a,b;
24 
25     while(scanf("%d%d",&a,&b)==2){
26     int i,temp,max=0;
27     for(i=a;i<=b;i++){
28         temp=div(i);
29             if(temp>=max)
30                 max=temp;
31     }
32 
33     cout<<max<<endl;
34     }
35 
36     return 0;
37 }
View Code

相关文章:

  • 2021-08-05
  • 2021-11-16
  • 2021-09-19
  • 2022-03-05
猜你喜欢
  • 2022-12-23
  • 2021-12-09
  • 2021-08-26
相关资源
相似解决方案