http://acm.hdu.edu.cn/showproblem.php?pid=1406
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 18009 Accepted Submission(s): 6640
2 2 5 5 7
0 1
#include<stdio.h> #include<string.h> int a[10010],b[10010]; void sum_factors()//N的因子之和为a[N]-N { int i,j; memset(a,0,sizeof(a)); for(i=1;i<10010;i++) for(j=1;j*i<10010;j++) a[j*i]+=i; } void judge() { sum_factors(); int i; for(i=1;i<10010;i++) if(a[i]-i==i) b[i]=1; } int main() { judge(); int N,num1,num2,sum,i; scanf("%d",&N); while(N--) { scanf("%d %d",&num1,&num2); if(num1>num2)//这里num1和num2关系不确定,开始没注意 {int t=num1;num1=num2;num2=t;} for(i=num1,sum=0;i<=num2;i++) if(b[i]==1) sum+=1; printf("%d\n",sum); } return 0; }