Codeforces Round #326 (Div. 2) B
因为质因数可以不用,所以要加一.
例如6=2x3,两个质因数都是一次,如果两个质因数都不用,它的一个因数是1;只用因数2,它的第二个因数就是2;只用因数3,它的第三个因数就是3;两个质因数都用,它的第四个因数就是6。
再如12=2²x3,两个质因数,2是2次,3是一次,如果两个质因数都不用,它的一个因数是1;只用一个因数2,它的第二个因数就是2;两个2都用,它的第三个因数就是4;不用3时就有3个因数,再用上3时就是(2+1)(1+1)=6个因数了。
2 seconds
256 megabytes
standard input
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.
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 indeed lovely.
AC代码
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
using namespace std;
const int maxn= ;
const int maxm= 1e4+;
const int inf = 0x3f3f3f3f;
typedef long long ll;
int main()
{
ll n;
while(scanf("%I64d",&n)!=EOF) //codeforces 不支持%lld
{
ll sum=;
for(int i=;i<=sqrt(n);i++) //要用sqrt函数 用i*i<=n 要把i定义为ll i*i会爆int
{
if(n%i==)
sum*=i;
while(n%i==) //除去倍数
n/=i;
}
printf("%I64d\n",sum*n);
}
return ;
}
Codeforces Round #326 (Div. 2) B的更多相关文章
- Codeforces Round #326 (Div. 2) D. Duff in Beach dp
D. Duff in Beach Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/probl ...
- Codeforces Round #326 (Div. 2) C. Duff and Weight Lifting 水题
C. Duff and Weight Lifting Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...
- Codeforces Round #326 (Div. 2) B. Duff in Love 分解质因数
B. Duff in Love Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/proble ...
- Codeforces Round #326 (Div. 2) A. Duff and Meat 水题
A. Duff and Meat Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/probl ...
- 很好的一个dp题目 Codeforces Round #326 (Div. 2) D dp
http://codeforces.com/contest/588/problem/D 感觉吧,这道题让我做,我应该是不会做的... 题目大意:给出n,L,K.表示数组的长度为n,数组b的长度为L,定 ...
- 「日常训练」Duff in the Army (Codeforces Round #326 Div.2 E)
题意(CodeForces 588E) 给定一棵\(n\)个点的树,给定\(m\)个人(\(m\le n\))在哪个点上的信息,每个点可以有任意个人:然后给\(q\)个询问,每次问\(u\)到\(v\ ...
- Codeforces Round #326 (Div. 2) B. Pasha and Phone C. Duff and Weight Lifting
B. Pasha and PhonePasha has recently bought a new phone jPager and started adding his friends' phone ...
- Codeforces Round #326 (Div. 2)-Duff in Love
题意: 一个数x被定义为lovely number需要满足这样的条件:不存在一个数a(a>1),使得a的完全平方是x的因子(即x % a2 != 0). 给你一个数n,求出n的因子中为love ...
- Codeforces Round #326 (Div. 2)-Duff and Meat
题意: Duff每天要吃ai千克肉,这天肉的价格为pi(这天可以买好多好多肉),现在给你一个数值n为Duff吃肉的天数,求出用最少的钱满足Duff的条件. 思路: 只要判断相邻两天中,今天的总花费 = ...
随机推荐
- iOS 让图片变模糊
#import <Accelerate/Accelerate.h> 1.初始化图片 UIImageView *iv = [[UIImageView alloc]initWithFrame: ...
- scala写算法-List、Stream、以及剑指Offer里部分题目基于scala解法
Stream(immutable) Stream是惰性列表.实现细节涉及到lazy懒惰求值.传名参数等等技术(具体细节详见维基百科-求值策略). Stream和List是scala中严格求值和非严格求 ...
- 编译c语言程序扩展ruby
环境: windows 10 64bit ruby 2.2.4p230 (2015-12-16 revision 53155) [i386-mingw32] gcc version 4.8.1 (GC ...
- @Data 注解引出的 lombok 小辣椒
今天在看代码的时候, 看到了这个注解, 之前都没有见过, 所以就查了下, 发现还是个不错的注解, 可以让代码更加简洁. 这个注解来自于 lombok,lombok 能够减少大量的模板代码,减少了在使用 ...
- bzoj 2298: [HAOI2011]problem a
Description 一次考试共有n个人参加,第i个人说:"有ai个人分数比我高,bi个人分数比我低."问最少有几个人没有说真话(可能有相同的分数) Input 第一行一个整数n ...
- Xamarin 简单的网络请求
//try //{ // var httpReq = (HttpWebRequest)HttpWebRequest.Create(new Uri(re ...
- C# 多线程传递多个参数
http://www.cnblogs.com/lvdongjie/p/5416883.html 3. 方式三:采用lambda表达式 对于lambda表达式不熟悉的可以查看微软MSDN上的说明文档.此 ...
- Python学习_10__python2到python3
同样作为动态语言,python的面相对像和ruby有很多类似的地方,这里还是推荐<Ruby元编程>一书来参考学习python的面向对象.然而python并不是纯面向对象设计,所以很多rub ...
- linux odbc连接sql server2014
首先坑爹呀!由于配置Zabbix 用到这个,网上资料一顿搜,一顿报错,调各种参数,依然无法连接,我竟无言以对: 这个只是项目的一小部分,只提供成功案例,没做深入研究,可以让遇到的兄弟少走弯路: 建议第 ...
- Python中的单例模式的几种实现方式的优缺点及优化
单例模式 单例模式(Singleton Pattern)是一种常用的软件设计模式,该模式的主要目的是确保某一个类只有一个实例存在.当你希望在整个系统中,某个类只能出现一个实例时,单例对象就能派上用场. ...