http://acm.hdu.edu.cn/showproblem.php?pid=1406
需要注意的地方:num1和num2的大小关系不确定。
![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#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 ;
}
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 ;
}