最多约数问题
暴力。
#include"iostream" #include"stdio.h" #include"cmath" using namespace std; int judge(int fac,int num) { int i; for(i=1;i<sqrt(num+0.0);i++) { if(num%i==0) fac+=2; } if(i==sqrt(num+0.0)) fac++; return fac; } int main() { freopen("E:\\in.txt","r",stdin); freopen("E:\\out.txt","w",stdout); int a,b; while(scanf("%d%d",&a,&b)==2) { int i,fac_num,max_num=0,num=a; for(i=a;i<=b;i++) { fac_num=judge(0,i); if(fac_num>max_num) { max_num=fac_num; num=i; } } cout<<max_num<<endl; } return 0; }