Codeforces 588B Duff in Love【暴力】水题
2017-06-30 17:20
579 查看
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.
![](http://codeforces.com/predownloaded/01/2d/012dd215c8c4fe26618c1deac16b705d6e91c093.png)
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.
Examples
Input
Output
Input
Output
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 indeed
lovely.
题目大意:
然你找到n的因子中(除了1以外)的最大的数,使得满足条件:
这个最大的因子数不能整除任意的平方数。
思路:
1、最大的因子可能是1e12.那么遍历平方数的时候需要O(sqrt(n))去遍历。
2、遍历找因子数的时候,同样需要O(sqrt(n))去遍历。
如果两层放在一起就是O(n)了吗?
显然不是,我们知道,对于一个数来讲,其因子数的个数不会很多,所以暴力找因子数然后O(sqrt(n))去遍历平方数是不会超时的。
Ac代码:
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
using namespace std;
#define ll __int64
int main()
{
ll n;
while(~scanf("%I64d",&n))
{
ll output=0;
for(ll i=1;i<=sqrt(n);i++)
{
if(n%i==0)
{
int flag=0;
for(ll j=2;j<=1000000;j++)
{
if(i%(j*j)==0)
{
flag=1;break;
}
}
if(flag==0)output=max(output,i);
flag=0;
for(ll j=2;j<=1000000;j++)
{
if((n/i)%(j*j)==0)
{
flag=1;break;
}
}
if(flag==0)output=max(output,n/i);
}
}
printf("%I64d\n",output);
}
}
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.
![](http://codeforces.com/predownloaded/01/2d/012dd215c8c4fe26618c1deac16b705d6e91c093.png)
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.
Examples
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 indeed
lovely.
题目大意:
然你找到n的因子中(除了1以外)的最大的数,使得满足条件:
这个最大的因子数不能整除任意的平方数。
思路:
1、最大的因子可能是1e12.那么遍历平方数的时候需要O(sqrt(n))去遍历。
2、遍历找因子数的时候,同样需要O(sqrt(n))去遍历。
如果两层放在一起就是O(n)了吗?
显然不是,我们知道,对于一个数来讲,其因子数的个数不会很多,所以暴力找因子数然后O(sqrt(n))去遍历平方数是不会超时的。
Ac代码:
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
using namespace std;
#define ll __int64
int main()
{
ll n;
while(~scanf("%I64d",&n))
{
ll output=0;
for(ll i=1;i<=sqrt(n);i++)
{
if(n%i==0)
{
int flag=0;
for(ll j=2;j<=1000000;j++)
{
if(i%(j*j)==0)
{
flag=1;break;
}
}
if(flag==0)output=max(output,i);
flag=0;
for(ll j=2;j<=1000000;j++)
{
if((n/i)%(j*j)==0)
{
flag=1;break;
}
}
if(flag==0)output=max(output,n/i);
}
}
printf("%I64d\n",output);
}
}
相关文章推荐
- codeforces 271A Beautiful Year(暴力水题)
- CodeForces 589I Lottery (暴力,水题)
- codeforces----2017 Hackatari Codeathon(A 暴力搜索 G概率)(水题DEH)
- CodeForces 711B Chris and Magic Square (暴力,水题)
- Codeforces-8VC Venture Cup 2016-Elimination Round-626A.暴力 626B.水题 626C.二分
- Codeforces 426 B Sereja and Mirroring【暴力枚举+模拟】水题
- Codeforces--366A--Dima and Guards(水题)
- Codeforces 891A Pride (dp & 数学 & 贪心 & 暴力)
- Codeforces 851A . Arpa and a research in Mexican wave 水题
- Codeforces 336C Vasily the Bear and Sequence 暴力
- CodeForces - 10A---水题
- codeforces 50A Domino piling(数学水题)
- codeforces 266A Stones on the Table(模拟水题)
- CodeForces 433C Ryouko's Memory Note-暴力
- Codeforces 490F. Treeland Tour 暴力+LIS
- Codeforces--660A--Co-prime Array(数学水题)
- Codeforces 592A PawnChess 【水题】
- Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)&&Codeforces 861A k-rounding【暴力】
- Codeforces 596A Wilbur and Swimming Pool 【水题】
- 【CodeForces 397A 】On Segment's Own Points(水题)