Code Forces 588 B. Duff in Love(数论)

Description
对于一个整数x,如果对于任意a>1都有x%(a^2)!=0,那么称x为可爱数,先给出一整数n,输出n的因子中最大的可爱数
Input
一个整数n
Output
n的因子中最大的可爱数
Sample Input
10
Sample Output
10
Solution
简单数论,将n分解素因子得到n=p1^k1*p2^k2*…pm^km,那么答案即为p1*p2*…*pk,简化一下过程就是while(n%(i*i)==0) n/=i;最后的n值即为答案
Code

#include<stdio.h>
typedef long long ll;
int main()
{
    ll n;
    while(~scanf("%I64d",&n))
    {
        for(ll i=2;i*i<=n;i++)
            while(n%(i*i)==0)
                n/=i;
        printf("%I64d\n",n);
    }
    return 0;
}

你可能感兴趣的:(Code Forces 588 B. Duff in Love(数论))