Codeforces Round #326 (Div. 2) B Duff in Love 简单数论 姿势涨
2015-11-08 21:17
411 查看
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.
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.
Sample test(s)
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 然你找到最大的一个数x x满足两个条件 1.是n的因子 2.x不能整除 任何正整数的平方
a题水果 看到这题 蒙蔽了 敲了一边 果然超时!!!打我呀?? 还不如不敲
补一下姿势 将n分解素因子得到n =p1^k1*p2^k2*…pm^km 例如 12=2^2*3^1
举一个例子 模拟一边 给将来 自己看
12 的因子 1 2 3 4 6 12
12=2^2*3^1
从2-->sqrt(12)=3
12%(2*2)==0-->n=12/2=6-->
6%(2*2)!=0->
i++-->3
3>sqrt(6)
break;
!!!!!sqrt(n)是为了保证素因子!!!
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.
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.
Sample test(s)
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 然你找到最大的一个数x x满足两个条件 1.是n的因子 2.x不能整除 任何正整数的平方
a题水果 看到这题 蒙蔽了 敲了一边 果然超时!!!打我呀?? 还不如不敲
补一下姿势 将n分解素因子得到n =p1^k1*p2^k2*…pm^km 例如 12=2^2*3^1
举一个例子 模拟一边 给将来 自己看
12 的因子 1 2 3 4 6 12
12=2^2*3^1
从2-->sqrt(12)=3
12%(2*2)==0-->n=12/2=6-->
6%(2*2)!=0->
i++-->3
3>sqrt(6)
break;
!!!!!sqrt(n)是为了保证素因子!!!
#include<bits/stdc++.h> using namespace std; int main() { __int64 n; scanf("%I64d",&n); for(__int64 i=2;i<=sqrt(n);i++) { while(n%(i*i)==0) n=n/i; } printf("%I64d\n",n); return 0; }
相关文章推荐
- 编程之美-电梯调度算法方法整理
- 快速排序
- HDU 2234 无题I
- scala + intellij idea 环境搭建及编译、打包
- 开始奋斗的程序媛
- Linux yum源完全配置
- 手机端实现Protocol Buffer
- Java Exception
- C语言实现链表之单向链表(九)在任意位置插入结点
- Codeforces Round #325 (Div. 1) 解题报告
- 相对定位与绝对定位
- 软件开发项目文档模版
- HDU 2918 Tobo or not Tobo
- QT 的信号与槽机制介绍
- MvvmLight框架使用入门(四)
- 20135223何伟钦—信息安全系统设计基础第九周学习总结
- 解决ubuntu14.04下Qt 5.3.1下的QtCreator fcitx,ibus不能输入中文
- c语言实现,图形界面扫雷
- 了解 Nginx 的 7 个原因(转)
- C语言实现链表之单向链表(八)删除尾结点