csu 1416 Practical Number(数论,结论题)
来源:互联网 发布:别墅网络覆盖方案 编辑:程序博客网 时间:2024/06/13 16:17
Practical Number
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 182 Solved: 48
[Submit][Status][Web Board]
Description
In number theory, a practical number is a positive integer n such that all smaller positive integers can be represented as sums of distinct divisors of n.
For example, 12 is a practical number because all the numbers from 1 to 11 can be expressed as sums of its divisors 1, 2, 3, 4, and 6: as well as these divisors themselves, we have 5 = 3 + 2, 7 = 6 + 1, 8 = 6 + 2, 9 = 6 + 3, 10 = 6 + 3 + 1, and 11 = 6 + 3 + 2. The first few practical numbers are: 1, 2, 4, 6, 8, 12, 16, 18, 20, 24, 28, 30, 32, 36, 40, 42, 48, 54, 56, 60.
Given a positive integer n, test if it is a practical number.
Input
The first line contains the number of test cases T (1 ≤ T ≤ 200).
For each test case, there is only one line with an integer n (1 ≤ n ≤ 1018) as defined above.
Output
For each test case, output “Yes” (without quotation marks) in one line if n is a practical number. Otherwise, output “No” (without quotation marks) instead.
Sample Input
1012345678910
Sample Output
YesYesNoYesNoYesNoYesNoNo
题意:给你一个n,问`1~n-1能否由n的约数相加得到思路:想了好久,最后百度了,挺无语的,居然是个结论题。
这现场赛出这种题目让人怎么解得出来啊~
关于结论可以看http://planetmath.org/PracticalNumber
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <queue>using namespace std;#define N 100008int prime[N],cnt,vis[N];void init(){ cnt=0; memset(vis,0,sizeof(vis)); for(int i=2;i<N;i++) { if(vis[i]) continue; prime[cnt++]=i; for(int j=i+i;j<N;j+=i) vis[j]=1; }}int solve(long long n){ if(n==1) return 1; if(n&1) return 0; long long now=1; for(int i=0;i<cnt;i++) { if(n%prime[i]==0) { if(prime[i]>now+1) return 0; long long temp=1,sum=1; while(n%prime[i]==0) { n/=prime[i]; temp*=prime[i]; sum+=temp; } now*=sum; } } if(n>now+1) return 0; return 1;}int main(){ int T; long long n; init(); scanf("%d",&T); while(T--) { scanf("%lld",&n); if(solve(n)) printf("Yes\n"); else printf("No\n"); } return 0;}
0 0
- csu 1416 Practical Number(数论,结论题)
- CSU 1416 Practical Number 很有意思的数学题
- csu 1756 prime(数论)
- CSU 1803:2016(数论)
- CSU 1209 Three Jugs (数论)
- CSU 1803 2016 (数论+思路)
- 常用数论结论
- 【数论】奇奇怪怪的结论
- HDOJ1005 Number Sequence(数论水题)
- HDU 4279 2012网络赛Number(数论 欧拉函数结论约数个数)
- [2017纪中10-26]数论 结论题
- CSU 1803 2016(数论)
- 【结论】【数论】欧拉定理
- HDU 4279 Number(数论)
- CSU 1522: Extravagant number
- 【结论】【数论】拓展欧几里得算法、费马小定理
- 一些数论的模板及相关结论
- 【jzoj4909】【李电下棋】【数论】【结论】
- 单选框的用法即几种常见对话框
- 带符号整数的除法与余数
- lightoj 1369 - Answering Queries (数学、规律、水)
- linux proc文件系统使用之单次读
- 浅谈EditText
- csu 1416 Practical Number(数论,结论题)
- 不等概率采样
- 暑期dp46道(43)--HDOJ 1159 最长公共子序列(可不连续)
- 对数组的验证
- DOMContentLoaded事件与load事件
- JAVA 日期处理
- epoll event触发问题
- 笔记:JavaMail邮件
- 安卓常用的第三方框架