csu 1416 Practical Number(数论,结论题)
2016-08-18 20:27
393 查看
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
10 1 2 3 4 5 6 7 8 9 10
Sample Output
Yes Yes No Yes No Yes No Yes No No
题意:给你一个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 100008
int prime
,cnt,vis
;
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;
}
相关文章推荐
- 数论结论 nefu 702
- 【结论】【数论】拓展欧几里得算法、费马小定理
- CSU 1416 Practical Number 很有意思的数学题
- 玲珑杯1144 - 数论你还会快速幂【结论+快速乘】
- 【结论】【数论】欧拉定理
- CSU 1803 2016(数论)
- CSU 1803:2016(数论)
- 数论在ACM中的几个常见应用结论
- csu 1320 Scoop water (数论)
- CSU 1871 中南大学网络赛E题 简单的数论
- csu 1756 prime(数论)
- 一些数论的模板及相关结论
- CSU 1803 2016 (数论+思路)
- 【BZOJ1416/1498】【NOI2006】神奇的口袋(数论,概率)
- 【数论】奇奇怪怪的结论
- hdu 5976 Detachment(数论,一个结论)
- Number Theory (Easy) SPOJ - NUMTRYE(数论)(结论类)
- csu 1756(数论+去重)
- CSU 1416 Practical Number
- CSU 1209 Three Jugs (数论)