NBUT 1223 Friends number
来源:互联网 发布:软件license @port lic 编辑:程序博客网 时间:2024/06/09 16:33
[1223] Friends number
- 时间限制: 1000 ms 内存限制: 131072 K
- 问题描述
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.
- 来源
辽宁省赛2010
题目意思是说,若一对正整数A和B,假设A的所有真因子(不含本身)之和为sumA,B的所有真因子(不含本身)之和为sumB,满足sumA=B ,sumB=A,这样的称为友谊数。输入给定的区间,输出区间内有多少对友谊数。分析:数据有500W,非常大,直接做是不可能的,那唯一的办法就是打表了。打表代码如下:#include<cstdio>#include<cstring>using namespace std;const int mx=5000000+10;int ans[mx];int main() { //freopen("out.txt","w",stdout); ans[0] = ans[1] = 1; memset(ans,0,sizeof(ans)); for(int i = 2; i <= mx; i++){ ans[i]++; for(int j = 2*i; j <= mx; j += i){ ans[j] += i; } } int cnt=0; for(int i = 2; i <= mx; i++){ if(ans[i] <= mx && i == ans[ans[i]] && i < ans[i]){ printf(" %d , %d , ",i,ans[i]); cnt++; if(cnt%4==0) puts(""); } }}
打表后就很简单了,AC代码如下:#include<cstdio>#include<cstring>using namespace std;int a[145]= { 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 , 503056 , 514736 , 522405 , 525915 , 600392 , 669688 , 609928 , 686072 , 624184 , 691256 , 635624 , 712216 , 643336 , 652664 , 667964 , 783556 , 726104 , 796696 , 802725 , 863835 , 879712 , 901424 , 898216 , 980984 , 947835 , 1125765 , 998104 , 1043096 , 1077890 , 1099390 , 1154450 , 1189150 , 1156870 , 1292570 , 1175265 , 1438983 , 1185376 , 1286744 , 1280565 , 1340235 , 1328470 , 1483850 , 1358595 , 1486845 , 1392368 , 1464592 , 1466150 , 1747930 , 1468324 , 1749212 , 1511930 , 1598470 , 1669910 , 2062570 , 1798875 , 1870245 , 2082464 , 2090656 , 2236570 , 2429030 , 2652728 , 2941672 , 2723792 , 2874064 , 2728726 , 3077354 , 2739704 , 2928136 , 2802416 , 2947216 , 2803580 , 3716164 , 3276856 , 3721544 , 3606850 , 3892670 , 3786904 , 4300136 , 3805264 , 4006736 , 4238984 , 4314616 , 4246130 , 4488910 , 4259750 , 4445050 };int main(){ int x,y; while(~scanf("%d%d",&x,&y)) { int cnt=0; for(int i=0;i<145;i+=2) { if(a[i]>=x && y>=a[i+1]) { //printf("%d %d\n",a[i],a[i+1]); cnt++; } } printf("%d\n",cnt); } return 0;}
0 0
- NBUT 1223 Friends number
- NBUT 1223 Friends number
- NBUT 1223 Friends number
- NBUT [1223] Friends number
- NBUT 1223 Friends number(打表)
- Friends number NBUT
- Friends number NBUT
- nbut [1223] Friends number 好题,打表法的求每个数的因子和
- Friends number
- Friends number
- NBUT [1464] Biggest Number dfs
- nyoj 411-Friends number
- nyoj 411 Friends number
- NBUT1223-Friends number
- NEU 1008 Friends number
- Friends number 数论 打表
- nefu 681 Friends number 神打表。。。。
- Friends number 2010辽宁省赛
- 移动端网页实现拨打电话功能的几种方法
- I Think I Need a Houseboat POJ 1005
- jpa的联合主键,级联操作和延迟加载
- Android IM(四)单人聊天和多人聊天(发送消息、接收消息)
- hdu 1671 Phone List && POJ 3630 Phone List(静态申请空间)
- NBUT 1223 Friends number
- 前端设计和开发的总结
- assert
- 使用javaHelp制作java swing帮助文档
- quartz定时任务时间设置
- 遍历Map的两种方法:keySet()和entrySet()
- jsch的简单使用
- poj3041
- 图片缓存之内存缓存技术LruCache,软引用