nefu 681 Friends number 神打表。。。。
2014-05-04 21:39
316 查看
http://acm.nefu.edu.cn/JudgeOnline/problemshow.php?problem_id=681
先打表计算出50000000内的所有兄弟数;
--------------------------------------------------------------------------------------------------------
打表程序:
-------------------------------------------------------------------------------------------------------
#include <string.h>
#include <iostream>
#include <stdio.h>
using namespace std;
int f(int x)
{
int cnt =0;
int cdd=0;
for(int i=1;i<x;i++)
if(x%i==0)
cnt+=i;
for(int i=1;i<cnt;i++)
if(cnt%i==0)
cdd+=i;
if(cdd==x)
return cnt;
return 0;
}
int main()
{
for(int i=1;i<=5000000;i++)
{
int cnt=f(i);
if(cnt!=0&&cnt>i)
printf("%d,%d\n",i,cnt);
}
return 0;
}
---------------------------------------------------------------------------------------------------
AC 代码:
#include <string.h>
#include <stdio.h>
#include <iostream>
using namespace std;
int fn[30][2]={
220,284,
1184,1210,
2620,2924,
5020,5564,
6232,6368,
10744,10856,
12285,14595,
17296,18416,
63020,76084,
66928,66992,
67095,71145,
69615,87633,
79750,88730,
100485,124155,
122265,139815,
122368,123152,
141664,153176,
142310,168730,
171856,176336,
176272,180848,
185368,203432,
196724,202444,
280540,365084,
308620,389924,
319550,430402,
356408,399592,
437456,455344,
469028,486178
};
int main()
{
int n,m,cnt;
while(~scanf("%d%d",&n,&m))
{
cnt=0;
for(int i=0;i<28;i++ )
if(fn[i][0]>=n&&fn[i][1]<=m)
cnt++;
printf("%d\n",cnt);
}
return 0;
}
description |
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]. |
input |
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. |
output |
For each test case, output the number of couples in the given range. The output of one test case occupied exactly one line. |
sample_input |
1 100 1 1000 |
sample_output |
0 1 |
hint |
6 is a number whose sum of all divisors is 6. 6 is not a friend number, these number is called Perfect Number. |
--------------------------------------------------------------------------------------------------------
打表程序:
-------------------------------------------------------------------------------------------------------
#include <string.h>
#include <iostream>
#include <stdio.h>
using namespace std;
int f(int x)
{
int cnt =0;
int cdd=0;
for(int i=1;i<x;i++)
if(x%i==0)
cnt+=i;
for(int i=1;i<cnt;i++)
if(cnt%i==0)
cdd+=i;
if(cdd==x)
return cnt;
return 0;
}
int main()
{
for(int i=1;i<=5000000;i++)
{
int cnt=f(i);
if(cnt!=0&&cnt>i)
printf("%d,%d\n",i,cnt);
}
return 0;
}
---------------------------------------------------------------------------------------------------
AC 代码:
#include <string.h>
#include <stdio.h>
#include <iostream>
using namespace std;
int fn[30][2]={
220,284,
1184,1210,
2620,2924,
5020,5564,
6232,6368,
10744,10856,
12285,14595,
17296,18416,
63020,76084,
66928,66992,
67095,71145,
69615,87633,
79750,88730,
100485,124155,
122265,139815,
122368,123152,
141664,153176,
142310,168730,
171856,176336,
176272,180848,
185368,203432,
196724,202444,
280540,365084,
308620,389924,
319550,430402,
356408,399592,
437456,455344,
469028,486178
};
int main()
{
int n,m,cnt;
while(~scanf("%d%d",&n,&m))
{
cnt=0;
for(int i=0;i<28;i++ )
if(fn[i][0]>=n&&fn[i][1]<=m)
cnt++;
printf("%d\n",cnt);
}
return 0;
}
相关文章推荐
- stormmedia文件夹,360downloads文件夹,FavoriteVideo文件夹是干什么的?
- 读<<大数据时代>>的一些感想
- fair调度器slot的配置
- Zynq 上的OpenCV加速学习
- Jeecms 源码剖析
- cocos2d-x 2.2 资源更新AssetsManager例子代码
- MSP430FR5739串口程序
- boost::serialization 拆分serialize函数
- mysql常用命令
- CISCO BGP协议精简技术要点
- java字体设置,包括大小,颜色,加粗,下划线,对齐,斜体的设置
- 读<<大数据时代>>的一些感想
- FloatyFish可行性研究报告
- 【笔记】设计模式——装饰者模式
- C语言学习笔记与总结(一)
- freemarker生成静态html文件
- IOS 线程处理 子线程的启动与结束
- 小白linux bash 学习二 shell Script
- 史上最强大的 Vim 代码补全引擎:YouCompleteMe
- 一张图看懂原码、反码、补码、移码