题目链接 :
http://codeforces.com/problemset/problem/588/B
题目大意:
这个题目的意思就是找出一个数中的因子,这个因子满足以下条件:
1、此数的因子没有完全平方数
2、是N中最大的因子
解题思路:
如果从1找到N,无疑会超时,所有我们只要从1到找sqrt(n)就好了,然后先判断从最大因子开始判断是否满足条件,若满足直接输出即可。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
using namespace std;
#define LL long long
LL sq[1000001];
int fun(LL x)
{
LL i;
for(i=2;i*i<=x;i++)
if(x%(i*i)==0) return 0;
return 1;
}
LL ma(LL x,LL y)
{
if(x>y) return x;
else return y;
}
int main()
{
LL i,j,n;
while(cin>>n)
{
int flag=0;
LL ans=1,m=sqrt(n+0.5)+1;
for(i=1;i<=m;i++)
{
LL k=n/i;
if(n%i==0&&fun(k))
{
flag=1;
ans=k;
break;
}
}
if(!flag)
for(i=m;i>=1;i--)
{
if(n%i==0&&fun(i))
{
ans=i;
break;
}
}
cout<<ans<<endl;
}
return 0 ;
}