1. 程式人生 > >Ural2102:Michael and Cryptography

Ural2102:Michael and Cryptography

fun 是不是 只有一個 HA devel cto factor 這一 題意

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

inputoutput
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個素數,然後判斷剩下的數是不是素數即可。

Ural2102:Michael and Cryptography