csu 1416 Practical Number(数论,结论题)

Practical Number

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 182   Solved: 48
[ Submit][ Status][ Web Board]

Description

In  number theory , a practical number  i s 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  ≤ 10 18 ) 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[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;
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值