A. Win or Freeze
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

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.

Examples
input

Copy
6
output
2
input

Copy
30
output
1
6
input

Copy
1
output
1
0
Note

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(简单的求质数问题)的更多相关文章

  1. 求质数算法的N种境界[1] - 试除法和初级筛法

    ★引子 前天,俺在<俺的招聘经验[4]:通过笔试答题能看出啥?>一文,以"求质数"作为例子,介绍了一些考察应聘者的经验.由于本文没有政治敏感内容,顺便就转贴到俺在CSD ...

  2. [经典算法] Eratosthenes筛选求质数

    题目说明: 除了自身之外,无法被其它整数整除的数称之为质数,要求质数很简单,但如何快速的求出质数则一直是程式设计人员与数学家努力的课题,在这边介绍一个著名的 Eratosthenes求质数方法. 题目 ...

  3. 【转】求质数算法的N种境界

    原文地址:http://blog.csdn.net/program_think/article/details/7032600/ ★引子 前天,俺在<俺的招聘经验[4]:通过笔试答题能看出啥?& ...

  4. (转)求质数算法的N种境界[1] - 试除法和初级筛法

    ★引子 前天,俺在<俺的招聘经验[4]:通过笔试答题能看出啥?>一文,以"求质数"作为例子,介绍了一些考察应聘者的经验.由于本文没有政治敏感内容,顺便就转贴到俺在CSD ...

  5. C语言程序设计100例之(12):Eratosthenes筛法求质数

    例12   Eratosthenes筛法求质数 问题描述 Eratosthenes筛法的基本思想是:把某范围内的自然数从小到大依次排列好.宣布1不是质数,把它去掉:然后从余下的数中取出最小的数,宣布它 ...

  6. C语言1-100连加,求质数,算瑞年检测字母大小写,登录系统

    #include <stdio.h> void test(){//1+2+3+4+.....+100 int a,b; a=0; b=0; for ( ; a<=100; a++) ...

  7. C语言程序设计100例之(11):求质数

    例11  求质数 问题描述 质数是指除了有1和自身作为约数外,不再有其他约数的数.比如:3.5.7是质数.而9不是质数,因为它还有约数3. 编写程序求给定区间中的所有质数. 输入格式 两个整数a和b, ...

  8. 小白的C++之路——求质数

    初学C++,打算用博客记录学习的足迹.写了两个求质数的程序,修修改改. #include <iostream> #include <math.h> using namespac ...

  9. Java实现欧拉筛与花里胡哨求质数高级大法的对比

    我也不清楚这是什么高级算法,欧拉筛是昨天有位大佬,半夜无意间告诉我的 欧拉筛: 主要的含义就是我把这个数的所有倍数都弄出来,然后下次循环的时候直接就可以跳过了 import java.text.Sim ...

随机推荐

  1. PHP的几种输出方式

    请写出echo.print_r.print.var_dump .die之间的区别 echo  只能输出字符串等单一数据 不能输出数据类型 不能输出数组等多种数据 print()  只能输出字符串等单一 ...

  2. Roman To Integer leetcode java

    问题描述: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range fr ...

  3. stl常用的查找算法

    #include<iostream> using namespace std; #include"vector" #include"algorithm&quo ...

  4. Beta阶段——第6篇 Scrum 冲刺博客

    Beta阶段--第6篇 Scrum 冲刺博客 标签:软件工程 一.站立式会议照片 二.每个人的工作 (有work item 的ID) 昨日已完成的工作 人员 工作 林羽晴 完成了函数的编写,提供报表数 ...

  5. PostgreSQL常用函数

    1.系统信息函数 1.会话信息函数 edbstore=# select current_catalog; #查询当前数据库名称 current_database ------------------ ...

  6. Oracle物理DG自动切换——Dataguard Broker配置

    1.前言部分 1.1 导读 各位技术爱好者,看完本文后,你可以掌握如下的技能: ① Data Guard Broker 的配置 ② Fast-Start Failover 的配置 ③ Oracle D ...

  7. 你还有没有印象?腾讯QQ16个版本界面你认识多少?

    腾讯公司成立于1998年11月11日(马化腾也曾经戏称“腾讯公司的生日被马云弄成双11购物节了”).1997年,马化腾接触到了ICQ:1998年11月11日,马化腾和同学张志东在广东省深圳市注册成立“ ...

  8. vue相关操作命令

    全局安装:npm install vue-cli -g 全局卸载:npm uninstall vue-cli -g 查看vue版本:vue -V 回车

  9. FastDFS安装教程

    1.下载 FastDFS下载:https://codeload.github.com/happyfish100/fastdfs/zip/master 库文件下载:https://codeload.gi ...

  10. weblogic补丁安装失败(Patch B25A is mutually exclusive and cannot coexist with patch(es): UIAL)

    由于曝出漏洞(CVE-2017-3248)需要将weblogic补丁更新至B25A,但是出现报错.如下: Conflict(s) detected - resolve conflict conditi ...