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. 如何使用mysql profiling功能分析单条查询语句

    Mysql从5.1版本开始引入show profile来剖析单条语句功能 一. 查看是否支持这个功能 yes表示支持 mysql> show variables like 'have_profi ...

  2. android ------ Emulator: error: x86 emulation currently requires hardware acceleration

    我创建 Android 模拟器,运行项目时出现了一个这样的错误: 如下: emulator ERROR:x86 emulation currently requires hardware accele ...

  3. ubuntu vi配置

    1.先卸载tiny版本vi 输入命令:sudo apt-get remove vim-common 2.然后再输入命令: sudo apt-get   install vim sudo vim /et ...

  4. [LintCode] Serialize and Deserialize Binary Tree(二叉树的序列化和反序列化)

    描述 设计一个算法,并编写代码来序列化和反序列化二叉树.将树写入一个文件被称为“序列化”,读取文件后重建同样的二叉树被称为“反序列化”. 如何反序列化或序列化二叉树是没有限制的,你只需要确保可以将二叉 ...

  5. 文件名简体转繁体bat

    @echo off rem 指定文件夹路径 set "fd=D:\下载的图片" rem 0为转换文件名,1为转换文件夹名,2为同时转换文件名和文件夹名 set f=0 rem 0为 ...

  6. Matlab:非线性热传导(抛物方程)问题

    函数文件1:real_fun.m function f=real_fun(x0,t0) %精确解 f=4*x0*(1-x0)*sin(t0); 函数文件2:F.m function f=F(N,u,U ...

  7. LINQ 初步了解

    .NET Framework 3.5的新特性 Language Integrated Query,即语言集成查询 查询 和语言结合关系数据库里的信息使用的XML文档保存在本地的DataSet内存中的L ...

  8. ASP.NET Core WebAPI 开发-新建WebAPI项目 转

    转 http://www.cnblogs.com/linezero/p/5497472.html ASP.NET Core WebAPI 开发-新建WebAPI项目   ASP.NET Core We ...

  9. fastjson SerializerFeature详解(转)

    原文地址:fastjson SerializerFeature详解

  10. spring cloud服务发现注解之@EnableDiscoveryClient与@EnableEurekaClient

    使用服务发现的时候提到了两种注解,一种为@EnableDiscoveryClient,一种为@EnableEurekaClient,用法上基本一致,今天就来讲下两者,下文是从stackoverflow ...