您的位置:首页 > 其它

【Codeforces Round 326 (Div 2)B】【质因数分解】Duff in Love n的最大因子使其不为平方数倍数

2015-11-10 10:18 399 查看
B. Duff in Love

time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
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.

Input
The first and only line of input contains one integer, n (1 ≤ n ≤ 1012).

Output
Print the answer in one line.

Sample test(s)

input
10


output
10


input
12


output
6


Note
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 indeedlovely.

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;}
template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;}
const int N=0,M=0,Z=1e9+7,ms63=1061109567;
int casenum,casei;
int main()
{
LL n;
while(~scanf("%lld",&n))
{
int top=sqrt(n);
LL ans=1;
for(int i=2;i<=top;i++)if(n%i==0)
{
ans*=i;
while(n%i==0)n/=i;
}
if(n)ans*=n;
printf("%lld\n",ans);
}
return 0;
}
/*
【题意】
给你一个n([1,1e12]),
我们想要找到n中的最大的一个因子,使得这个因子不是任何平方数的倍数。

【类型】
质因数分解

【分析】
不是任何平方数的倍数,等价于不是任何素数的倍数。
不是任何素数的倍数,等价于任何素数这个数都最多只含有一个。
于是我们对n做素数拆分,所有其因子素数的单次乘积结果,就是答案啦。

【时间复杂度&&优化】
O(sqrt(n))

*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息