Friends number NBUT - 1223 (暴力打表)
2017-04-10 19:58
260 查看
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.
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.
//对5000000之内的每个数的所有因子暴力打表求和竟然不会超时,我擦。。。很强 #include<map> #include<set> #include<queue> #include<stack> #include<vector> #include<math.h> #include<cstdio> #include<sstream> #include<numeric>//STL数值算法头文件 #include<stdlib.h> #include <ctype.h> #include<string.h> #include<iostream> #include<algorithm> #include<functional>//模板类头文件 using namespace std; typedef long long ll; const int maxn=11000; const int INF=0x3f3f3f3f; int f[5000010]; int xA[200],xB[200]; int main() { for(int i=1; i<=5000000; i++)//暴力打表,把每个数的所以因子的和求出来 { int xsk=i+i; while(xsk<=5000000) { f[xsk]+=i;//f函数存储的是每个数所以因子的和 xsk+=i; } } int sum=0; for(int i=1; i<=5000000; i++) { int A=i,B=f[i]; if(B>A&&B<5000000&&f[B]==i) { xA[sum]=A; xB[sum]=B; sum++; } } int L,R; while(~scanf("%d%d",&L,&R)) { int ans=0; for(int i=0; i<sum; i++) { if(xA[i]>=L&&xA[i]<=R&&xB[i]>=L&&xB[i]<=R) ans++; } printf("%d\n",ans); } return 0; }
相关文章推荐
- Friends number NBUT - 1223 (暴力打表)
- nbut [1223] Friends number 好题,打表法的求每个数的因子和
- 湖南大学ACM程序设计新生杯大赛(同步赛) D -Number 【打表+暴力】
- Harmonic Number LightOJ - 1234 (暴力打表,区域保存)
- NBUT 1223 Friends number (打表)
- HDU 5648 DZY Loves Math 暴力打表
- cellForRowAtIndexPath not called but numberOfRowsInSection called
- D - 最大数maxnumber HYSBZ - 1012 (巧妙暴力,单调栈,据说树状数组线段树都能做~这俩有点大材小用了)
- 暴力求解——打表,暴力
- Serial number is not available when doing any inventory transaction but shows in on hand quantity in
- number 90分的暴力
- MDK:test.axf: Error: L6630E: Invalid token start expected number or ( but found n at position 5 on l
- CodeForces 204A - Little Elephant and Interval 算答案..易错..暴力打表对拍
- hdu5451 矩阵快速幂+暴力打表循环节
- Number Sequence 【打表】+【找规律】
- hdu - beautiful number-5179 - 暴力打表&DFS&数位DP
- All but a finite number
- UESTC Memory 1262 (打表&暴力模拟)
- hdu 4608 I - I-number()(高精度+暴力)
- ZOJ-3768:Continuous Login(打表找规律+暴力)