NYOJ 411 Friends number (数论--因子和)
来源:互联网 发布:淘宝宝贝标题范文 编辑:程序博客网 时间:2024/05/19 13:29
链接:点击打开链接
题意:
Friends number
时间限制:2000 ms | 内存限制:65535 KB
难度:2
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 1001 1000
- 样例输出
01
- 提示
- 6 is a number whose sum of all divisors is 6. 6 is not a friend number, these number is called Perfect Number.
- 来源
- 辽宁省10年省赛
oj数据有点大,常规方法,一个劲的超时,看了一下排在前几名的人的代码,基本都是打表过,(囧~~),后来有点提示,用数组模拟过了,其实还可以用容器
,那样写的话看的比较舒服。
代码:(红色区域重点)
#include <stdio.h>#include <iostream>#include <string.h>#include <algorithm>using namespace std;#define N 5000001#define CLR(arr, what) memset(arr, what, sizeof(arr))int a[N] ,pre[N],last[N],ss=0;void getsum();int main(){ //getsum();// for(int i = 2; i <= N; i++) a[i] = 1;// for(int i = 2; i * i <= N; i++)// for (int j = i; j * i <= N; j++)// a[i * j] += i + j; <span style="color:#ff0000;"> for(int i = 2; i <= N; i++) a[i] = 1; for(int i = 2; i * i <= N; i++) for(int j = i + 1; i * j <= N; j++) a[i * j] += i + j; for(int i = 2; i * i <= N; i++) a[i * i] += i; for(int i=1; i<=N; i++) { int t=a[i]; if (t > i && t <=N&& a[t] == i) { pre[ss]=i; last[ss]=t; ss++; } }</span> int m,i,j,n; while(~scanf("%d%d",&m,&n)) { int count = 0; for(i=0; i<ss; i++) if(pre[i]>=m&&last[i]<=n) count++; printf("%d\n",count); } return 0;}
When you want to give up, think of why you persist until now!
0 0
- NYOJ 411 Friends number (数论--因子和)
- nyoj 411-Friends number
- nyoj 411 Friends number
- Friends number 数论 打表
- NYOJ 928 小M的因子和(数论)
- Friends number (筛法打表求因子,水题)
- NEU 1008 Friends number 数论 打表
- Friends number (数论,打表)
- nbut [1223] Friends number 好题,打表法的求每个数的因子和
- NYOJ-520 最大素因子【数论】
- NYOJ 767 因子和
- nyoj-767-因子和
- NYOJ 767 因子和
- NYOJ 767 因子和
- nyoj 因子和 746
- NYOJ 767 因子和
- NYOJ 509 因子和阶乘
- NYOJ 509 因子和阶乘
- Vericut05_与NX连接
- 【IOS源码】智能聊天机器人源码—仿微信界面
- (简单母函数模板)hdu 1028 Ignatius and the Princess III
- (1.1.6.1)一个例子让你搞懂“指针和引用”以及const的用法、空指针
- URAL 1607. Taxi
- NYOJ 411 Friends number (数论--因子和)
- 自定义UIViewController转场、GPUImage
- [HTML][CSS]table中加边框的样式(所有td都加薄边框)
- Android开发--教你巧妙应对屏幕旋转
- Socket编程
- 将nodejs设置成开机自动启动
- 寻找数组中最大值
- 模糊查询mybatis
- (平方幂母函数)hdu 1398 Square Coins