2 seconds
256 megabytes
standard input
standard output
Duff is in love with lovely numbers! A positive integer x is called lovely if and only if there is no such positive integer a > 1 such that a2 is a divisor of x.
Malek has a number store! In his store, he has only divisors of positive integer n (and he has all of them). As a birthday present, Malek wants to give her a lovely number from his store. He wants this number to be as big as possible.
Malek always had issues in math, so he asked for your help. Please tell him what is the biggest lovely number in his store.
The first and only line of input contains one integer, n (1 ≤ n ≤ 1012).
Print the answer in one line.
10
10
12
6
In first sample case, there are numbers 1, 2, 5 and 10 in the shop. 10 isn't divisible by any perfect square, so 10 is lovely.
In second sample case, there are numbers 1, 2, 3, 4, 6 and 12 in the shop. 12 is divisible by 4 = 22, so 12 is not lovely, while 6 is indeed lovely.
题意:给一个数n 然你找到最大的一个数x x满足两个条件 1.是n的因子 2.x不能整除 任何正整数的平方
a题水果 看到这题 蒙蔽了 敲了一边 果然超时!!!打我呀?? 还不如不敲
补一下姿势 将n分解素因子得到n =p1^k1*p2^k2*…pm^km 例如 12=2^2*3^1
举一个例子 模拟一边 给将来 自己看
12 的因子 1 2 3 4 6 12
12=2^2*3^1
从2-->sqrt(12)=3
12%(2*2)==0-->n=12/2=6-->
6%(2*2)!=0->
i++-->3
3>sqrt(6)
break;
!!!!!sqrt(n)是为了保证素因子!!!
#include<bits/stdc++.h>
using namespace std;
int main()
{
__int64 n;
scanf("%I64d",&n);
for(__int64 i=2;i<=sqrt(n);i++)
{
while(n%(i*i)==0)
n=n/i;
}
printf("%I64d\n",n);
return 0;
}