hdu1406

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

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

15103755_f4nz.gif 15103755_AxVa.gif 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 ;
}

转载于:https://my.oschina.net/garyun/blog/602889

猜你喜欢

转载自blog.csdn.net/weixin_33932129/article/details/91773943
今日推荐