codeforces - 326B - Duff in Love(练习)
来源:互联网 发布:sqlserver 对等发布 编辑:程序博客网 时间:2024/05/29 04:34
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.
这题RE的我够心塞,RE了两次!!wa我就认了吧,竟然会RE QAQ心情是沉痛的。
题意:就是给一个n,输出他的最大的约数,而且这个约数不能被n其他约数的平方整除。
如果是质数的话,那就是n本身。如果是合数,扫一遍n的约数会超时,所以扫了n的开方次约数,然后n%约数== 0, 则也是n的约数,这样复杂度就降下来啦。只是判断的时候光顾着看平方后的范围了,没注意扫到n也是要停的QAQ
#include <iostream>#include <algorithm>#include <cstdio>#include <cmath>#include <cstring>#include <cstdlib>#include <iostream>#include <stack>#include <queue>#define INF 0x3f3f3f3fusing namespace std;long long a[10000005];int main(){ long long n; while(scanf("%I64d", &n) != EOF) { long long k = 0; long long ans; for(long long i = 1; i * i <= n; i++) { if(n % i == 0) a[k++] = i; } if(k == 1) ans = n; else { long long kk = k; for(int i = 0; i < kk; i++) { if((n % a[i] == 0) && ((n / a[i]) > a[kk - 1])) a[k++] = n / a[i]; } sort(a, a + k); for(long long i = k - 1; i >= 0; i--) { long long flag = 0; for(long long j = 1; a[j] * a[j] <= a[i] && j < k; j++) //最开始没有写j<k QAQ RE的好难过,还蠢蠢的找了半天错误T T { long long m = a[j] * a[j]; if(a[i] % m == 0) { flag = 1; break; } } if(flag == 0) //flag = 0 就是这个约数不是任何约数平方的倍数啦,就是答案喵 { ans = a[i]; break; } } } printf("%I64d\n", ans); } return 0;}
- codeforces - 326B - Duff in Love(练习)
- codeforces#326-B-Duff in Love-暴力
- Codeforces Round #326 (Div. 2)B. Duff in Love
- Codeforces Round #326 (Div. 2) 588 B. Duff in Love
- Codeforces Round #326 (Div. 2) B. Duff in Love
- Codeforces Round #326 (Div. 2)B. Duff in Love
- codeforces 588 B Duff in Love
- Codeforces 588B Duff in Love 【数学】
- CodeForces 588B Duff in Love
- B. Duff in Love
- B. Duff in Love
- B - Duff in Love(数论)
- Codeforces 588B Duff in Love【暴力】水题
- Codeoforces 558 B. Duff in Love 【 Codeforces Round #326 (Div. 2)】
- Codeforces Round #326 (Div. 2) B. Duff in Love (分解质因子)
- Code Forces 588 B. Duff in Love(数论)
- coderforce 588B Duff in Love
- CF 588B Duff in Love
- opencv3 绘制一维直方图-灰度直方图的绘制-柱状图
- 【深入Java虚拟机】之一:Java内存区域与内存溢出
- 黑马程序员——Java基础---多线程(2)
- opencv3 计算二维直方图-H-S直方图
- ant编译web工程
- codeforces - 326B - Duff in Love(练习)
- iOS开发基本技能之JSON
- Build path entry is missing: org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.
- 关于C/C++一些面试/笔试题的反思(超基础的知识点)
- redis 学习笔记(2)-client端示例代码
- Ubuntu 命令行修改网络配置方法
- 约瑟夫环
- php连接mysql的问题
- nginx不浏览直接下载文件