The hacker Michael develops breakthrough password manager, which is called KEK (Keeper of Encrypted Keys). A distinctive feature of KEK is excellent security. To achieve this, Michael had to develop innovative encryption scheme. For example, in the well-known RSA scheme the sum of prime powers in the factorization is equal to 2, whereas in Michael’s scheme this sum is equal to 20!
However, the current version of the KEK runs very slow. Michael has found out that the problem is in the function of checking a modulus for correctness. This function should take the number n and answer, whether the sum of prime powers included in the factorization of n is equal to 20. Can you do this quickly?
Remember that the factorization of an integer is the representation of it in the form like p 1 α1 · p 2 α2 · ... · p k αk, where p i are prime numbers, and α i > 0. It is known that such representation is unique. Then the sum of powers looks likeα 1 + α 2 + ... + α k.

Input

The only line contains an integer n (1 ≤ n ≤ 10 18).

Output

If the sum of prime powers, included in the factorization of n, is equal to 20, then output “Yes”, otherwise output “No”.

Example

input output
2
No
1048576
Yes
10000000000
Yes

题意:给定数字N(1e18级),问将其唯一分解后(N=a1^p1*a2^p2...),幂的和(p1+p2+p3...)是否为20。

思路:根号N等于1e9级别,显然不能普通地分解因子来做。但是注意到20比较小,可以从20出发考虑:

将N分解后不可能有两个大于1e6的因子。因为1e6*1e6*2^18>2e18。认识到这一点,说明最多只有一个大于1e6的因子。所以只要在[1,1e6]找19个素数因子,然后判断剩下的数是不是素数即可。

#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
const int maxn=;
int p[maxn+],vis[maxn+],cnt;
void getprime()
{
for(int i=;i<=maxn;i++){
if(!vis[i]) p[++cnt]=i;
for(int j=;p[j]*i<=maxn;j++){
vis[i*p[j]]=;
if(i%p[j]==) break;
}
}
}
bool isprime(ll x)
{
for(int i=;i*i<=x;i++)
if(x%i==) return false;
return true;
}
int main()
{
getprime();
ll N; int num=;
scanf("%lld",&N);
if(N<*){
printf("No\n");
return ;
}
for(int i=;i<=cnt;i++){
while(N%p[i]==){
N/=p[i]; num++;
if(num==&&N==){ printf("Yes\n"); return ;}
if(num>=){ printf("No\n");return ;}
}
}
if(num<) printf("No\n");
else if(num==&&N>&&isprime(N)) printf("Yes\n");
else printf("No\n");
return ;
}

Ural2102:Michael and Cryptography(数论&素数)的更多相关文章

  1. ACM数论-素数

    ACM数论——素数  素数定义: 质数(prime number)又称素数,有无限个.质数定义为在大于1的自然数中,除了1和它本身以外不再有其他因数,这样的数称为质数.例 子:2.3.5.7.11.1 ...

  2. 【线性筛】【筛法求素数】【素数判定】URAL - 2102 - Michael and Cryptography

    暴力搞肯定不行,因此我们从小到大枚举素数,用n去试除,每次除尽,如果已经超过20,肯定是no.如果当前枚举到的素数的(20-已经找到的质因子个数)次方>剩下的n,肯定也是no.再加一个关键的优化 ...

  3. LightOJ-1259 Goldbach`s Conjecture 数论 素数筛

    题目链接:https://cn.vjudge.net/problem/LightOJ-1259 题意 给一个整数n,问有多少对素数a和b,使得a+b=n 思路 素数筛 埃氏筛O(nloglogn),这 ...

  4. ACM/ICPC 之 数论-素数筛选法 与 "打表"思路(POJ 1595)

    何为"打表"呢,说得简单点就是: 有时候与其重复运行同样的算法得出答案,还不如直接用算法把这组数据所有可能的答案都枚举出来存到一个足够大的容器中去-例如数组(打表),然后再输入数据 ...

  5. code vs1706 求合数和(数论 素数的判定)

    1706 求合数和  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 白银 Silver 题解  查看运行结果     题目描述 Description 用户输入一个数,然后输出 ...

  6. code vs1436 孪生素数 2(数论+素数的判定)

    1436 孪生素数 2  时间限制: 2 s  空间限制: 1000 KB  题目等级 : 白银 Silver 题解  查看运行结果     题目描述 Description 如m=100,n=6 则 ...

  7. 数论 - 素数的运用 --- poj 2689 : Prime Distance

    Prime Distance Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12512   Accepted: 3340 D ...

  8. P1218 [USACO1.5]特殊的质数肋骨 Superprime Rib (数论—素数 + DFS)

    这大概是我写的第一个DFS 题目描述 农民约翰的母牛总是产生最好的肋骨.你能通过农民约翰和美国农业部标记在每根肋骨上的数字认出它们.农民约翰确定他卖给买方的是真正的质数肋骨,是因为从右边开始切下肋骨, ...

  9. (第三场) H Diff-prime Pairs 【数论-素数线性筛法+YY】

    题目链接 题目描述 Eddy has solved lots of problem involving calculating the number of coprime pairs within s ...

随机推荐

  1. PTA 02-线性结构4 Pop Sequence (25分)

    题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/665 5-3 Pop Sequence   (25分) Given a stack wh ...

  2. 【状压DP】OpenJ_POJ - C17K Lying Island

    https://vjudge.net/contest/171652#problem/K [题意] 小岛上有n个人,有些是好人(一定是真话),有些是坏人(可能是真话也可能是假话),现在要判断最多有多少好 ...

  3. LCA 在线倍增法 求最近公共祖先

    第一步:建树  这个就不说了 第二部:分为两步  分别是深度预处理和祖先DP预处理 DP预处理: int i,j; ;(<<j)<n;j++) ;i<n;++i) ) fa[i ...

  4. boost thread 在非正常退出时 内存泄露问题

    在使用boost的thread库的时候,如果主程序退出,thread创建的线程不做任何处理,则会出现内存泄露. 解决方法: 在主线程退出时,对所有thread使用interrupt()命令,然后主程序 ...

  5. [Bzoj1069][Scoi2007]最大土地面积(凸包)(旋转卡壳)

    1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 3629  Solved: 1432[Submit][Sta ...

  6. 2017多校Round10(hdu6171~hdu6181)

    补题进度:5/11 1001(双向BFS) 题意: 给你一个类似移子游戏,给你初始状态和终止状态,问初始状态到终止状态至少要移多少步,如果步数>20就-1 分析: 很明显的BFS了,不过普通的B ...

  7. ArrayList内部实现原理

    数组在创建的时候长度是固定的,那么就有往ArrayList中不断添加对象的时候,那么ArrayList是如何管理这些数组的? ArrayList内部通过Object[]实现,我们通过分析ArrayLi ...

  8. ABP每次生成前都执行bundle设置

    ABP项目每次编译mvc项目时都会执行bundle,比较耗时. 可以在项目文件(*.csproj)中发现设置了每前生成前执行的命令 <Target Name="PreBuild&quo ...

  9. 巧用MySQL AHI加速神器,让你的InnoDB查询飞起来!

    DBAPLUS  http://mp.weixin.qq.com/s/cIjQIz-ZngSYJ3k2ZBBSsg

  10. uva558 Wormholes SPFA 求是否存在负环

    J - Wormholes Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Stat ...