问题 : Friends number
时间限制: 1 Sec 内存限制: 128 MB</center>
题目描述
Paula and Tai are couple. There are many stories between them. The day Paula left by airplane, Tai send one message to telephone 2200284, then, everything is changing… (The story in “the snow queen”).
After a long time, Tai tells Paula, the number 220 and 284 is a couple of friends number, as they are special, all divisors of 220’s sum is 284, and all divisors of 284’s sum is 220. Can you find out there are how many couples of friends number less than 10,000. Then, how about 100,000, 200,000 and so on.
The task for you is to find out there are how many couples of friends number in given closed interval [a,b]。
输入
There are several cases.
Each test case contains two positive integers a, b(1<= a <= b <=5,000,000).
Proceed to the end of file.
输出
For each test case, output the number of couples in the given range. The output of one test case occupied exactly one line.
样例输入
1 100
1 1000
样例输出
0
1
提示
6 is a number whose sum of all divisors is 6. 6 is not a friend number, these number is called Perfect Number.
解题思路
先直接暴力打表,再判断。
代码如下:
#include <stdio.h>
int s[56][2] = {
220,284,284,220,1184,1210,
1210,1184,2620,2924,
2924,2620,5020,5564,
6232,6368,6368,6232,
10744,10856,10856,10744,
12285,14595,14595,12285,
17296,18416,18416,17296,
63020,76084,66928,66992,
66992,66928,67095,71145,
69615,87633,71145,67095,
76084,63020,79750,88730,
87633,69615,88730,79750,
100485,124155,122265,139815,
122368,123152,123152,122368,
124155,100485,139815,122265,
141664,153176,142310,168730,
153176,141664,168730,142310,
171856,176336,176272,180848,
176336,171856,180848,176272,
185368,203432,196724,202444,
202444,196724,203432,185368,
280540,365084,308620,389924,
319550,430402,356408,399592,
365084,280540,389924,308620,
399592,356408,430402,319550,
437456,455344,455344,437456,
469028,486178,486178,469028};
int main()
{
int a, b, ans;
while(~scanf("%d%d",&a,&b))
{
ans = 0;
for(int i = 0; i < 56; i++)
if(a <= s[i][0] && s[i][0] < s[i][1] && s[i][1] <= b)
ans++;
printf("%d\n", ans);
}
return 0;
}