Codeforces Round #326 (Div. 2)-Duff in Love
题意:
一个数x被定义为lovely number需要满足这样的条件:不存在一个数a(a>1),使得a的完全平方是x的因子(即x % a2 != 0)。
给你一个数n,求出n的因子中为lovely number的最大因子。
思路:
由于1<=n<=0=109,所以我们只要从1到找sqrt(n)就好,然后先从最大因子开始判断是否满足lovely number的条件,当满足时直接出输出即可.
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <ctime>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <iterator>
#include <vector> using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define MAXN 10000010
#define MAXM 1000010 int fun(LL x)
{
LL i;
for(i = ; i*i <= x; i++ )
if(x%(i*i)==)
return ;
return ;
} int main()
{
int flag;
LL n, m, i, j, ans;
while(scanf("%lld", &n)==)
{
flag = ;
m = sqrt(n+0.5)+;
for(i = ; i <= m; i++ )
{
LL k = n/i;
if(n%i==&&fun(k))
{
flag = ;
ans = k;
break;
}
}
if(!flag)
for(i = m; i >= ; i--)
{
if(n%i==&&fun(i))
{
ans = i;
break;
}
}
printf("%lld\n", ans);
} return ;
}
Codeforces Round #326 (Div. 2)-Duff in Love的更多相关文章
- Codeforces Round #326 (Div. 2)-Duff and Meat
题意: Duff每天要吃ai千克肉,这天肉的价格为pi(这天可以买好多好多肉),现在给你一个数值n为Duff吃肉的天数,求出用最少的钱满足Duff的条件. 思路: 只要判断相邻两天中,今天的总花费 = ...
- 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 ...
- 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 ...
- 「日常训练」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 Duff in Love 简单数论 姿势涨
B. Duff in Love time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #326 (Div. 1) - C. Duff in the Army 树上倍增算法
题意:一个n个点的数, m个人住在其中的某些点上, 每个人的标号1-m, 询问u-v 路径上标号前a个人,并输出标号,a < 10. 作法, 利用倍增, ID[j][i] 表示i到i的第2^j个 ...
随机推荐
- AngularJS中service,factory,provider的区别(转载:http://my.oschina.net/tanweijie/blog/295067)
目录[-] 一.service引导 二.service 1.factory() 2.service() 3.provider() 一.service引导 刚开始学习Angular的时候,经常 ...
- MyBatis——Mybatis缓存
原文:http://www.cnblogs.com/xdp-gacl/p/4270403.html MyBatis学习总结(七)--Mybatis缓存 一.MyBatis缓存介绍 正如大多数持久层框架 ...
- 在Windows和Linux上安装paramiko模块
一.paramiko模块有什么用? paramiko是用python语言写的一个模块,遵循SSH2协议,支持以加密和认证的方式,进行远程服务器的连接.由于使用的是python这样的能够跨平台运行的语言 ...
- XMPP 常见错误:(<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-autho
1检查jid XMPP认证的问题,一般都是与JID有关的,因此解决这类问题,首选的入口就是分析一下XMPPStream的JID,客户端在与服务器连接后,Socket就绑定了这个端口,用来处理与服务器的 ...
- js获取时间格式化
http://www.cnblogs.com/zhangpengshou/archive/2012/07/19/2599053.html
- RequireJS加载ArcGIS API for JavaScript
1.在main.js中配置ArcGIS API for JavaScript require.config({ paths : { //arcgisJS "esri": " ...
- win8style布局
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" ...
- Python顺序集合之 tuple
慕课网<Python 入门>学习笔记 1.tuple特性 tuple是另一种有序的列表,中文翻译为“ 元组 ”.tuple 和 list 非常类似,但是,tuple一旦创建完毕,就不能修改 ...
- Android画一条横线
<View android:layout_width="match_parent" android:layout_height="1px" android ...
- 无法启动T-SQL 调试
问题详情 解决办法 1.要在服务器本机,不要远程 2.用实例名,不要用.或者local 3.以Windows身份验证的administrator或者sqlserver身份验证的sa登录