Duff in Love(素因子的应用)
来源:互联网 发布:淘宝卖家如何开通天猫 编辑:程序博客网 时间:2024/05/20 10:13
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 indeedlovely.
这题一开始就想用这种方法,但是却在判断时间复杂度上被自己的智商蠢哭了,我竟然认为那个while循环也是O(n)的。这题一开始根本不知道是素数的应用,不过好像与因子有关的都与素数有关。
AC代码:
#include<iostream>#include<algorithm>#include<cstring>#include<vector>#include<cstdio>#include<cmath>using namespace std;#define CRL(a) memset(a,0,sizeof(a))typedef __int64 ll;#define T 1000005int main(){ /* freopen("input.txt","r",stdin);*/ll n,i;while(~scanf("%I64d",&n)){ll sum=1; for(i=2;i*i<=n;++i){ if(n%i==0){ sum*=i; while(n%i==0)n/=i; } } printf("%I64d\n",sum*n);}return 0;}
- Duff in Love(素因子的应用)
- B - Duff in Love(数论)
- B. Duff in Love
- B. Duff in Love
- Duff in Love
- Codeforces Round #326 (Div. 2) B. Duff in Love (分解质因子)
- 【Codeforces Round 326 (Div 2)B】【质因数分解】Duff in Love n的最大因子使其不为平方数倍数
- Code Forces 588 B. Duff in Love(数论)
- codeforces - 326B - Duff in Love(练习)
- codeforces#326-B-Duff in Love-暴力
- coderforce 588B Duff in Love
- CF 588B Duff in Love
- codeforces 588 B Duff in Love
- Codeforces 588B Duff in Love 【数学】
- (Duff in Love)唯一分解定理
- CodeForces 588B Duff in Love
- Codeforces Round #326 (Div. 2)B. Duff in Love
- Codeforces Round #326 (Div. 2) 588 B. Duff in Love
- mapReduce体系结构和各种算法 笔记六
- 关于spring3使用AOP编程时需要引入哪些jar包的问题
- php执行shell脚本命令
- 4.1.2 有效矩形和无效矩形
- 通过MapReduce程序实现对hbase表数据的插入
- Duff in Love(素因子的应用)
- 279.Perfect Squares
- 自己的学习博客
- 当对象类型是一个接口的时候,在Eclipse中如果跳转到该接口对应的实现类
- 让ipad的绘画功能不再是鸡肋,wacom发布Intuos Creative压感触控笔
- poj2392 1742多重背包
- 设计模式-观察者模式自我理解
- C# Stopwatch的用法
- hive的UDF