codeforce150A(简单的求质数问题)
2 seconds
256 megabytes
standard input
standard output
You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer q. During a move a player should write any integer number that is a non-trivial divisor of the last written number. Then he should run this number of circles around the hotel. Let us remind you that a number's divisor is called non-trivial if it is different from one and from the divided number itself.
The first person who can't make a move wins as he continues to lie in his warm bed under three blankets while the other one keeps running. Determine which player wins considering that both players play optimally. If the first player wins, print any winning first move.
The first line contains the only integer q (1 ≤ q ≤ 1013).
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64dspecificator.
In the first line print the number of the winning player (1 or 2). If the first player wins then the second line should contain another integer — his first move (if the first player can't even make the first move, print 0). If there are multiple solutions, print any of them.
6
2
30
1
6
1
1
0
Number 6 has only two non-trivial divisors: 2 and 3. It is impossible to make a move after the numbers 2 and 3 are written, so both of them are winning, thus, number 6 is the losing number. A player can make a move and write number 6 after number 30; 6, as we know, is a losing number. Thus, this move will bring us the victory.
只要找到p除1和本身外的两个质因素1就一定赢
#include<stdio.h>
#include<math.h>
int check(__int64 n)
{
__int64 i,k;
for(i=2;i<=sqrt(n);i++)
{
if(n%i==0)
return 0;
}
return 1;
}
int main()
{
__int64 q;
__int64 i,sum,k;
scanf("%I64d",&q);
sum=1;
k=1;
for(i=2;i<=sqrt(q);i++)
{
if(q%i==0&&check(i))
{
//printf("W%d\n",i);
sum++;
if(i*i<q&&q%(i*i)==0)//注意当i的平方也是q的因数时i可以当两个质数用
{
printf("1\n%I64d\n",i*i);
return 0;
}
k*=i;
if(sum>=3)
{
printf("1\n%I64d\n",k);
return 0;
}
}
}
if(sum==1)
printf("1\n0\n");
else
printf("2\n");
return 0;
}
codeforce150A(简单的求质数问题)的更多相关文章
- 求质数算法的N种境界[1] - 试除法和初级筛法
★引子 前天,俺在<俺的招聘经验[4]:通过笔试答题能看出啥?>一文,以"求质数"作为例子,介绍了一些考察应聘者的经验.由于本文没有政治敏感内容,顺便就转贴到俺在CSD ...
- [经典算法] Eratosthenes筛选求质数
题目说明: 除了自身之外,无法被其它整数整除的数称之为质数,要求质数很简单,但如何快速的求出质数则一直是程式设计人员与数学家努力的课题,在这边介绍一个著名的 Eratosthenes求质数方法. 题目 ...
- 【转】求质数算法的N种境界
原文地址:http://blog.csdn.net/program_think/article/details/7032600/ ★引子 前天,俺在<俺的招聘经验[4]:通过笔试答题能看出啥?& ...
- (转)求质数算法的N种境界[1] - 试除法和初级筛法
★引子 前天,俺在<俺的招聘经验[4]:通过笔试答题能看出啥?>一文,以"求质数"作为例子,介绍了一些考察应聘者的经验.由于本文没有政治敏感内容,顺便就转贴到俺在CSD ...
- C语言程序设计100例之(12):Eratosthenes筛法求质数
例12 Eratosthenes筛法求质数 问题描述 Eratosthenes筛法的基本思想是:把某范围内的自然数从小到大依次排列好.宣布1不是质数,把它去掉:然后从余下的数中取出最小的数,宣布它 ...
- C语言1-100连加,求质数,算瑞年检测字母大小写,登录系统
#include <stdio.h> void test(){//1+2+3+4+.....+100 int a,b; a=0; b=0; for ( ; a<=100; a++) ...
- C语言程序设计100例之(11):求质数
例11 求质数 问题描述 质数是指除了有1和自身作为约数外,不再有其他约数的数.比如:3.5.7是质数.而9不是质数,因为它还有约数3. 编写程序求给定区间中的所有质数. 输入格式 两个整数a和b, ...
- 小白的C++之路——求质数
初学C++,打算用博客记录学习的足迹.写了两个求质数的程序,修修改改. #include <iostream> #include <math.h> using namespac ...
- Java实现欧拉筛与花里胡哨求质数高级大法的对比
我也不清楚这是什么高级算法,欧拉筛是昨天有位大佬,半夜无意间告诉我的 欧拉筛: 主要的含义就是我把这个数的所有倍数都弄出来,然后下次循环的时候直接就可以跳过了 import java.text.Sim ...
随机推荐
- gitignore有时候为啥过滤不了文件或目录
一.问题介绍 使用Git过程中,有时候我们想过滤项目中的部分文件,在.gitignore中加入该文件名称或该文件所在目录的名称,比如我们的项目日志文件(.log文件) 但是有时候发现不管用.不好使. ...
- 抽离amazeUI里面的弹出框
花了一些时间读了amazeUI的源码 把他的弹出框给单独抽离出来了,具体可以见源码:http://pan.baidu.com/s/1mibQ9T2
- IBM messed up *AGAIN* in their thinkpad: 0xA0000 -> 0x9F000
/* * IBM messed up *AGAIN* in their thinkpad: 0xA0000 -> 0x9F000. * They seem to have don ...
- android --------学习流程图
如何快速入门和进阶安卓开发,是很多技术小白的疑问. 大家都知道,Android开发要学的技能非常多,技术更新速度还快,但是总的来说:掌握最核心的技术,最规范的开发流程,成为专业.出色的安卓开发工程师也 ...
- Confluence 6 应该如何在我的空间中组织内容
页面和博客 你在 Confluence 中创建的任何内容,从会议记录到回顾和任何中间的内容,不管来源是博客和页面. 你的主页将是任何访问你网站中的用户首先看到的内容.为了让用户更加容易的找到他们需要查 ...
- wdcp环境redis的位置
- 2.2 UML用例模型
参与者(Actor) 参与者(注:有另一种翻译“执行者”) 代表位于系统之外并和系统进行交互的一类事物(人.物.其他软件子系统等) 通过它,可以对软件系统与外界发生的交互进行分析和描述 通过它,可以了 ...
- 【洛谷p2312】解方程
(清明培训qwq,明天就要回学校了qwq拒绝) 行吧我洛谷都四天没碰了 解方程[传送门] 算法标签: (作为一个提高+省选-的题) 丁大佬真的很有幽默感emmm: #include <cstdi ...
- 【洛谷p2822】组合数问题
(突然想 ??忘掉了wdt) (行吧那就%%%hmr) 组合数问题[传送门] (因为清明要出去培训数学知识所以一直在做数论) 组合数<=>杨辉三角形(从wz那拐来的技能 ...
- python中RabbitMQ的使用(路由键)
1.简介 当我们希望每个接收端接收各自希望的消息时,我们可以使用路由键,此时交换机的类型为direct. 2.工作原理 每个接收端的消息队列在绑定交换机的时候,可以设定相应的路由键. 发送端通过交换机 ...