Friends number 数论 打表
来源:互联网 发布:vr相机软件 编辑:程序博客网 时间:2024/05/03 01:40
题目描述:
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 <=500,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.
原先设计了个算法。交上去2000多MS。。超时了。。后来输出全部数据。。发现答案最多只有28.。。打表。
这是我用于打表的代码
- /*
- * @user ipqhjjybj
- * @Time
- * @data 20130629
- */
- #include <cstdio>
- #include <cmath>
- #include <cstdlib>
- #include <ctime>
- #include <iostream>
- #include <cmath>
- #include <algorithm>
- #include <numeric>
- #include <utility>
- #include <cstring>
- #include <vector>
- #include <stack>
- #include <queue>
- #include <map>
- #include <string>
- using namespace std;
- #define inf 0x3f3f3f3f
- #define MAXN 500010
- #define clr(x,k) memset((x),(k),sizeof(x))
- #define clrn(x,k) memset((x),(k),(n+1)*sizeof(int))
- #define cpy(x,k) memcpy((x),(k),sizeof(x))
- #define Base 10000
- typedef vector<int> vi;
- #define foreach(it,c) for(vi::iterator it = (c).begin();it != (c).end();++it)
- #define max(a,b) ((a)>(b)?(a):(b))
- #define min(a,b) ((a)<(b)?(a):(b))
- int num[500020];
- void getSumDivider(int n){
- int k,i,j;
- for(i = 0;i <= n;i++) num[i]=0;
- for(i = 2;i <= n;i++) num[i]+=1;
- for(i = 2;i+i <= n;i++){
- for(j = i+i,k=2;j <= n;j+=i,k++){
- num[j]+=k;
- }
- }
- }
- int main(){
- freopen("1008.out","w",stdout);
- int a,b,aaa,bbb,i,ans;
- getSumDivider(MAXN);
- //while(scanf("%d %d",&a,&b)!=EOF){
- a = 1;b = 500000;
- ans=0;
- for(i = a;i <= b;i++){
- aaa = num[i];
- if(aaa>b)continue;
- bbb = num[aaa];
- if(bbb == i && a <= aaa && aaa <= b && aaa != bbb)
- {
- printf("%d,%d,\n",i,aaa);
- ans++;
- }
- }
- printf("%d\n",ans/2);
- //}
- return 0;
- }
这是我最终AC 的代码:
- /*
- * @user ipqhjjybj
- * @Time
- * @data 20130629
- */
- #include <stdio.h>
- #include <stdlib.h>
- int Ans[56][2]={
- 220,284,
- 284,220,
- 1184,1210,
- 1210,1184,
- 2620,2924,
- 2924,2620,
- 5020,5564,
- 5564,5020,
- 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,i;
- while(scanf("%d %d",&a,&b)!=EOF){
- ans=0;
- for(i=0;i<56;i++)
- if(a<=Ans[i][0]&&Ans[i][0]<Ans[i][1]&&Ans[i][1]<=b)
- ans++;
- printf("%d\n",ans);
- }
- return 0;
- Friends number 数论 打表
- NEU 1008 Friends number 数论 打表
- Friends number (数论,打表)
- NBUT1223 Friends number(打表,暴力)
- NBUT 1223 Friends number(打表)
- [hdu 4215]Number Theory? 数论+打表
- NYOJ 411 Friends number (数论--因子和)
- Friends number
- Friends number
- hdu 1215 数论 +打表
- UVA305 - Joseph(数论 + 打表)
- UVA 1583 打表 数论
- HDU 1215(数论,打表 - -|)
- HDU 2136(数论,筛选打表)
- hdu 2136 数论+筛选质数+打表
- UVA138(数论问题二分打表)
- lightoj-1289(数论+素数打表)
- Num(数论(或打表))
- PHP5.5 将会带来哪些新特征
- English Game 字典树排序 字符串处理
- cocos2d-瓷砖地图格式
- 实验五 Linux操作系统是如何工作的?
- 用Bat命令重启Explorer
- Friends number 数论 打表
- 尝试SQL Server 2014 OLTP memory-optimized表遇到的问题
- 学习Spring框架系列(四):IoC和AOP的应用——事务配置
- DatabaseMetaData之获取数据库所有表
- 读《穷爸爸与富爸爸》引发的思考
- Android http 多线程下载心得
- 64位机 ptrace问题
- ubuntu 常用命令总结
- 佛道相争---阐述了之间的区别