【CodeForces - 151C】Win or Freeze (博弈,数学,唯一素数分解)

题干:

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-trivialdivisor 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 %I64d specificator.

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

6

Output

2

Input

30

Output

1
6

Input

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 6is 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.

题目大意:

  博弈问题,题目给了我们一个数,然后让俩个人轮换操作:可以把这个数换成他的非平凡因数(但是不能是1和它本身),如果那个人不能操作了,那么他就胜利。第一个人胜利,则输出它的第一场操作。每个人都希望自己胜利,也就是不会失误。

解题报告:

   我们想要胜利,也就是想让自己不能操作,也就是如果我制造出一个只有两个质数的数,这样对手只能取走其中一个,那么我们走不动了,我们就赢了。所以我们面对一个数,我们的必败态就是,它是由两个素数组成的。所以我们对n做唯一性分解这个题就做完了。再看一眼数据范围,n可以等于1,所以加个特判。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
ll n;
ll biao[MAX];
int cnt;
bool is(ll x) {for(ll i = 2; i*i<=x; i++) {if(x%i==0) return 0;}return 1 ;
}
void fenjie(ll x) {for(ll i = 2; i*i<=x; i++) {if(x%i == 0 && is(i)) {//biao[++cnt] = i;while(x%i==0) biao[++cnt]=i,x/=i;}if(cnt>=2) break;}if(x>1) biao[++cnt]=x;
}
int main()
{cin>>n;if(n==1 || is(n)) {puts("1");puts("0");return 0 ;}fenjie(n);if(cnt == 2 && biao[1]*biao[2] == n) {puts("2");}else {puts("1");printf("%lld\n",biao[1]*biao[2]);}return 0 ;}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441149.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

vs怎么把textbox输入的实数放置变量里_方程的计算机处理96(3)_C++vs

计算机语言运用--数值计算9-方程的计算机处理96(3)_Cvs计算机&#xff1a;电子线路组成的计算机器。人与计算机则是通过计算机语言-符号系统说给计算机听而交流。计算机语言有低级语言-机器语言、汇编、高级语言-C/C/C#/VB/PASCAL/LISP/JAVA/PYTHON/……成百上千种之多。作为一…

【CodeForces - 151D】Quantity of Strings (字符串问题,思维推导,有坑)

题干&#xff1a; Just in case somebody missed it: this winter is totally cold in Nvodsk! It is so cold that one gets funny thoughts. For example, lets say there are strings with the length exactly n, based on the alphabet of size m. Any its substring with…

2008r装mysql_mysql5.7.17在win2008R2的64位系统安装与配置实例

安装MySql操作系统&#xff1a;Windows Server 2008 R2 StandardMySql版本&#xff1a;mysql-5.7.17-winx64第一步&#xff1a;解压mysql-5.7.17-winx64.zip到指定位置第二步&#xff1a;安装文件根目录下添加data文件夹&#xff0c;将my-default.ini重命名为my.ini第三步&…

【POJ - 2377】Bad Cowtractors (最大生成树,并查集)

题干&#xff1a; Bessie has been hired to build a cheap internet network among Farmer Johns N (2 < N < 1,000) barns that are conveniently numbered 1..N. FJ has already done some surveying, and found M (1 < M < 20,000) possible connection route…

csv转为utf8编码_读取UTF8编码的CSV并转换为UTF-16

我正在读取具有UTF8编码的CSV文件&#xff1a;ifile open(fname, "r")for row in csv.reader(ifile):name row[0]print repr(row[0])这很好用&#xff0c;并打印出我希望它打印出来的东西; UTF8编码 str &#xff1a;> \xc3\x81lvaro Salazar> \xc3\x89lodie…

【 CodeForces - 799A 】Carrot Cakes(模拟,细节,有坑)

题干&#xff1a; In some game by Playrix it takes t minutes for an oven to bake k carrot cakes, all cakes are ready at the same moment t minutes after they started baking. Arkady needs at least n cakes to complete a task, but he currently dont have any. H…

mysql 递归实现树形_Mysql实现树形递归查询

最近在做项目迁移&#xff0c;Oracle版本的迁到Mysql版本&#xff0c;遇到有些oracle的函数&#xff0c;mysql并没有&#xff0c;所以就只好想自定义函数或者找到替换函数的方法进行改造。Oracle递归查询oracle实现递归查询的话&#xff0c;就可以使用start with ... connect b…

【CH - 1401】 兔子与兔子(字符串哈希)

题干&#xff1a; 描述 很久很久以前&#xff0c;森林里住着一群兔子。有一天&#xff0c;兔子们想要研究自己的 DNA 序列。我们首先选取一个好长好长的 DNA 序列&#xff08;小兔子是外星生物&#xff0c;DNA 序列可能包含 26 个小写英文字母&#xff09;&#xff0c;然后我…

postmain请求中午乱码_完美解决Get和Post请求中文乱码的问题

对于Post请求&#xff0c;只需在Servlet或者jsp中写入如下代码就可以把解决从表单中传入的中文乱码问题request.setCharacterEncoding("utf-8");而对于Get请求&#xff0c;因为请求参数会被附加到地址栏的URL之后&#xff0c;所以不能用上面的处理方法。应该这样&…

【HDU - 5187】zhx's contest (快速幂+ 快速乘,模板)

题干&#xff1a; 2018百度之星复赛晋级名单出炉&#xff08;增加20%晋级名额&#xff09;~ zhxs contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 3779 Accepted Submission(s): 1226 Problem Desc…

python批量打印word_Python使用扩展库pywin32实现批量文档打印实例

本文代码需要正确安装Python扩展库pywin32&#xff0c;建议下载whl文件进行离线安装。然后调用win32api的ShellExecute()函数来实现文档打印&#xff0c;系统会根据文档类型自动选择不同的软件进行打开并自动打印&#xff0c;如果要打印的是图片的话&#xff0c;需要手工确认一…

【牛客 - 283E】贪心只能过样例(模拟)

题干&#xff1a; 小西是单身狗&#xff0c;所以她不喜欢看到有CP在秀恩爱&#xff01; 有一天&#xff0c;小西出来闲逛&#xff0c;发现街上的行人都排成了一排&#xff0c;并且可以用这种形式表示&#xff1a; MMFMMFFFMMM 其中M表示男孩子&#xff0c;F表示女装的男孩…

apmserver导入MySQL_mysql数据库导入导出

window下1.导出整个数据库mysqldump -u 用户名 -p 数据库名 > 导出的文件名mysqldump -u dbuser -p dbname > dbname.sql2.导出一个表mysqldump -u 用户名 -p 数据库名 表名> 导出的文件名mysqldump -u dbuser -p dbname users> dbname_users.sql3.导出一个数据库结…

【牛客 - 283C】模拟只会猜题意(简单模拟)

题干&#xff1a; 小西突然觉得回文串是一种非常优雅的东西&#xff0c;她突然想要把身边所有的字符串都变成回文&#xff01; 所谓回文串就是一个倒置后仍与自身相等的字符串&#xff0c;如“gxuacmmcauxg”和“gxuacmcauxg”。 小西不喜欢单身狗&#xff0c;所以小西只会…

sql开启mysql远程连接_SQLServer2008设置开启远程连接

SQLServer2008设置开启INTERNET远程连接 SQL Server 2008默认是不允许远程连接的&#xff0c;sa帐户默认禁用的&#xff0c;如果想要在本地用SSMS连接远程服务器上的SQL Server 2008&#xff0c;需要做两个部分的配置&#xff1a; 使用sa账户登录SQL Server Management Studio(…

【牛客 - 283H】图论一顿套模板(思维转化,Dijkstra)

题干&#xff1a; 由于临近广西大学建校90周年校庆&#xff0c;西大开始了喜闻乐见的校园修缮工程&#xff01; 然后问题出现了&#xff0c;西大内部有许许多多的道路&#xff0c;据统计有N栋楼和M条道路&#xff08;单向&#xff09;&#xff0c;每条路都有“不整洁度”W&…

spss相关性分析看结果_spss相关性分析

当我们想要了解变量的相关程度时,就需要用到相关分析,而相关分析也是回归之前很重要的一步,通常用到的方法是pearson方法。 首先解释一下相关系数,相关系数反应的是两个变量之间变化趋势的方向以及程度,其值范围为-1到+1,正值表示正相关,负值表示负相关,绝对值越大表示…

【牛客 - 283F】出装方案(最小费用最大流)

题干&#xff1a; 众所周知&#xff0c;在各种对抗类游戏里装备都是很重要的一环&#xff0c;不同的出装方案会给玩家带来不同的强度。 dalao手里有N件装备&#xff0c;现在dalao要把装备分给N个队友&#xff0c;每个队友只能分一件装备&#xff0c;而每个队友穿上不同的装…

mysql瓶颈分析_网站瓶颈分析—MYSQL性能分析

一、关于慢查询设置和分析查找慢查询参数mysql> show variables like long%;---------------------------| Variable_name | Value |---------------------------| long_query_time | 10.000000 |---------------------------mysql> show variables like slow%;---------…

【CodeForces - 289C】Polo the Penguin and Strings (水题,字符串,思维构造,有坑)

题干&#xff1a; Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the strings length e…