CodeForces 588B
题目链接 :
http://codeforces.com/problemset/problem/588/B
题目大意:
这个题目的意思就是找出一个数中的因子,这个因子满足以下条件:
1、此数的因子没有完全平方数
2、是N中最大的因子
解题思路:
如果从1找到N,无疑会超时,所有我们只要从1到找sqrt(n)就好了,然后先判断从最大因子开始判断是否满足条件,若满足直接输出即可。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
using namespace std;
#define LL long long LL sq[1000001];
int fun(LL x)
{
LL i;
for(i=2;i*i<=x;i++)
if(x%(i*i)==0) return 0;
return 1;
} LL ma(LL x,LL y)
{
if(x>y) return x;
else return y;
} int main()
{ LL i,j,n; while(cin>>n)
{ int flag=0;
LL ans=1,m=sqrt(n+0.5)+1;
for(i=1;i<=m;i++)
{
LL k=n/i;
if(n%i==0&&fun(k))
{
flag=1;
ans=k;
break;
}
} if(!flag)
for(i=m;i>=1;i--)
{ if(n%i==0&&fun(i))
{
ans=i;
break;
}
} cout<<ans<<endl;
}
return 0 ;
}
CodeForces 588B的更多相关文章
- Codeforces Round #326(Div2)
CodeForces 588A 题意:Duff喜欢吃肉,想在接下来的n天,每天都有Ai斤肉吃,但每一天肉的单价Pi不定,肉 可以保存不过期,现已知n天每天肉的斤数Ai,以及单价Pi,为了使每天都 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- javascript中,你真的会用console吗?
使用console进行性能测试和计算代码运行时间 对于前端开发人员,在开发过程中经常需要监控某些表达式或变量的值,如果使用用debugger会显得过于笨重,最常用的方法是会将值输出到控制台上方便调试. ...
- java 基本类型和包装类的比较
public class BoxingTest { @Test public void test1(){ String a = new String("1"); String b ...
- JS escape()、encodeURI()和encodeURIComponent()的区别
1.实例说明: var url='http://wx.jnqianle.com/content/images/冰皮月饼.jpg?name=张三丰&age=11'; console.info(w ...
- wpf 调用线程必须为sta 因为许多ui组件都需要
解决 办法 public void SomeMethod() { var task = System.Windows.Application.Current.Dispatcher.BeginInvok ...
- 我的第一个boke
哈哈哈 接口
- [LeetCode OJ] Single Number之二 ——Given an array of integers, every element appears THREE times except for one. Find that single one.
class Solution { public: int singleNumber(int A[], int n) { ; ; ; i<=bits; i++) { ; ; ; j<n; j ...
- 原生javascript写的侧栏跟随效果
浏览网站时经常看到有的网站上,当一个页面很长的时候,设定侧栏内容会跟随滚动条滚动,我们把这种效果叫做“侧栏跟随滚动”.这种特效对提高网站浏览量.文章点击率.广告点击量都有一定效果. 侧栏跟随滚动的实现 ...
- 前端模板文件化jQuery插件 $.loadTemplates
工作中使用前端模板引擎,如 artTemplate.jsRender,来替代拼接字符串. 可是直接把模板写在页面上会带来页面臃肿,模板无法重用,与 ASP.NET等后端语言语法冲突等问题. 所以将多个 ...
- C#/.NET整数的三种强制类型转换(int)、Convert.ToInt32()、int.Parse()的区别
这三种方式都是强制把内容转换为整数,但他们之间是有区别的,如下: 一.(int)适合简单数据类型之间的转换,C#的默认整型是int32(不支持bool型). 二.int.Parse(string sP ...
- Telerik_2012_Q3 破解全套下载链接
1.Telerik_OpenAccess_ORM_2012_3_1012_SDK.zip (暂未提供下载) 2. Telerik_OpenAccess_ORM_2012_3_1012.zip 3. T ...