hdu1406

http://acm.hdu.edu.cn/showproblem.php?pid=1406

需要注意的地方:num1和num2的大小关系不确定。

View Code
#include"iostream"
using namespace std;
int v[10000];
void Init()
{
int i,j;
memset(v,
0,sizeof(v));
for(i=2; i<10000; i++)
{
int sum=0;
for(j=1;j<=i/2;j++)
{
if(i%j==0) sum+=j;
}
if(sum==i) { v[i]=1; }
}
}
int main()
{
int t,a,b;
cin
>>t;
Init();
while(t--)
{
cin
>>a>>b;
int count=0;
if(a>b)
{
int temp=a;
a
=b;
b
=temp;
}
for(int i=a;i<=b;i++)
{
if(v[i]==1) count++;
}
cout
<<count<<endl;
}
return 0;
}
posted @ 2011-04-22 18:33  聊聊IT那些事  阅读(268)  评论(0编辑  收藏  举报