Codeforces 588B Duff in Love【暴力】水题
来源:互联网 发布:程序员算法是什么 编辑:程序博客网 时间:2024/05/19 23:25
Duff is in love with lovely numbers! A positive integer x is called lovely if and only if there is no such positive integera > 1 such that a2 is a divisor ofx.
Malek has a number store! In his store, he has only divisors of positive integern (and he has all of them). As a birthday present, Malek wants to give her alovely 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 islovely.
In second sample case, there are numbers 1, 2, 3, 4, 6 and 12 in the shop. 12 is divisible by4 = 22, so 12 is notlovely, 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 __int64int 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 588B Duff in Love【暴力】水题
- codeforces#326-B-Duff in Love-暴力
- codeforces 588 B Duff in Love
- Codeforces 588B Duff in Love 【数学】
- CodeForces 588B Duff in Love
- Codeforces Round #326 (Div. 2) 588 B. Duff in Love
- B. Duff in Love
- B. Duff in Love
- coderforce 588B Duff in Love
- CF 588B Duff in Love
- Codeforces Round #326 (Div. 2)B. Duff in Love
- Codeforces Round #326 (Div. 2) B. Duff in Love
- codeforces - 326B - Duff in Love(练习)
- Codeforces Round #326 (Div. 2)B. Duff in Love
- Code Forces 588 B. Duff in Love(数论)
- B - Duff in Love(数论)
- Codeoforces 558 B. Duff in Love 【 Codeforces Round #326 (Div. 2)】
- Codeforces Round #326 (Div. 2) B. Duff in Love (分解质因子)
- ToLua学习笔记,创建自定义矩阵类
- CSS字体垂直、水平居中
- Shell 正则表达式
- Android模拟器Genymotion使用详解
- 网络服务器select
- Codeforces 588B Duff in Love【暴力】水题
- TinkPHP 自定义API基控制器类
- vue.js,基础用法实例
- Sublime 个人配置+Python环境
- Android 后台运行那些事
- 进程同步3 补充:数据的加锁操作
- libc++abi.dylib`__cxa_throw: 使用[AVAudioPlayer play]会产生__cxa_throw异常
- 信息安全(ssl、数字证书、数字签名、加密算法)
- iOS 应用的签名原理是什么?