ACdream 1115 Salmon And Cat (找规律&&打表)
来源:互联网 发布:mac放置文件 编辑:程序博客网 时间:2024/05/22 12:32
题目链接:传送门
题意:
一个数被认为是一个完美的数,只要需要满足以下的两个条件之一
1)x = 1 or 3
2)x = 2 + a*b + 2*a + 2*b; a,b都是完美的数。
分析:
x + 2 = (a + 2)*(b + 2)
由于x1=1,x2=3,所有的数都是由着两个数衍生而来。那么我们就可
以得出一个结论了,一个数x如果是完美的数,那么x = 3^p*5^q;
因此代码如下:
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <queue>#include <set>#include <map>using namespace std;int main(){ int n; while(~scanf("%d",&n)){ n+=2; while(n%3==0) n/=3; while(n%5==0) n/=5; if(n!=1) puts("No"); else puts("Yes"); } return 0;}
还可以打表把1e9以内的所有完美数打出来。
代码如下:
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <queue>#include <set>#include <map>using namespace std;typedef long long LL;LL a[140]={1,3,7,13,23,25,43,73,79,123,133,223,241,373,403,623,673,727,1123,1213,1873,2023,2185,3123,3373,3643,5623,6073,6559,9373,10123,10933,15623,16873,18223,19681,28123,30373,32803,46873,50623,54673,59047,78123,84373,91123,98413,140623,151873,164023,177145,234373,253123,273373,295243,390623,421873,455623,492073,531439,703123,759373,820123,885733,1171873,1265623,1366873,1476223,1594321,1953123,2109373,2278123,2460373,2657203,3515623,3796873,4100623,4428673,4782967,5859373,6328123,6834373,7381123,7971613,9765623,10546873,11390623,12301873,13286023,14348905,17578123,18984373,20503123,22143373,23914843,29296873,31640623,34171873,36905623,39858073,43046719,48828123,52734373,56953123,61509373,66430123,71744533,87890623,94921873,102515623,110716873,119574223,129140161,146484373,158203123,170859373,184528123,199290373,215233603,244140623,263671873,284765623,307546873,332150623,358722673,387420487,439453123,474609373,512578123,553584373,597871123,645700813,732421873,791015623,854296873,922640623,996451873,};int main(){ int n; while(~scanf("%d",&n)){ int ans = 0; for(int i=0;i<137;i++) if(a[i]==n) ans = 1; if(ans) puts("Yes"); else puts("No"); } return 0;}
1 0
- ACdream 1115 Salmon And Cat (找规律&&打表)
- Alarm(找规律+素数打表)
- Number Sequence 【打表】+【找规律】
- hdu_6124_打表_找规律
- ACdream 1213 Matrix Multiplication【水题 、 找规律】
- surfaces,sprites and salmon
- zoj 3622 Magic Number (找规律+打表)
- hdu 4664 Triangulation(博弈论 sg找规律打表)
- UVA 10706 Number Sequence (找规律 + 打表 + 查找)
- URAL 1385 Interesting Number (暴力打表 + 找规律)
- hdoj 1005 Number Sequence (找规律,打表)
- 2659: [Beijing wc2012]算不出的算式 打表+找规律
- ZOJ 3939 The Lucky Week 找规律打表
- FZU 2037Maximum Value Problem (打表预处理/找规律)
- ZOJ 3939The Lucky Week (打表预处理/找规律)
- 玲珑学院-1010-Alarm【打表】【找规律】【思维】
- 玲珑学院OJ 1010 - Alarm(找规律+打表)
- hdu 5512 Pagodas【暴力打表+找规律】
- C++创建对象的两种方法
- QT获取时间
- arm处理器启动流程分析
- LINUX重启MYSQL的命令
- 树莓派安装node.js
- ACdream 1115 Salmon And Cat (找规律&&打表)
- WebStorm:令人眼前一亮的一款前端开发IDE
- Linux手动安装Mysql
- 反射
- git 命令简要
- 从缓存行出发理解volatile变量、伪共享False sharing、disruptor
- 3.1.2 字符串格式化
- 嵌入式Linux 挂载完根文件系统后,自动执行的文件分析
- 会议