Codeforces 151C(分解因数)
来源:互联网 发布:多可网络爬虫 编辑:程序博客网 时间:2024/05/22 15:29
问题描述:
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.
InputThe 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.
OutputIn 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.
input
6
output
2
题目题意:题目给了我们一个数,然后让俩个人对数操作即:可以把这个数换成他的因数(但是不能是1和它本身),如果那个人不能操作了,那么他就胜利。第一个人胜利,则输出它的第一场操作
题目分析:仔细想一下不能发现,其实第一个人胜利的机会很大,只要它第一个数换的好的话!我们假设第一个人把数换成原数的最小俩个因子的积,那么肯定就是他赢了,如果没有的话,那么肯定2赢了。
代码如下:
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#define ll long longusing namespace std;ll factor[100],fcnt;bool check(ll n){ for (int i=2;i<=(int) sqrt(n);i++) { if (n%i==0) return false; } return true;}int main(){ ll n,m; while (cin>>n) { fcnt=0; m=n; if (n==1||check(n)) {//质数也是他赢 printf("%d\n%d\n",1,0); continue; } for (int i=2;i<=(int)sqrt(n);i++) { if (n%i==0) { while (n%i==0) { factor[fcnt++]=i; n=n/i; if (fcnt>=2) break; } } if (fcnt>=2) break; } // cout<<factor[0]<<" "<<factor[1]<<endl; if (fcnt>=2&&factor[0]*factor[1]!=m) {//还要避免是它本身 printf("1\n"); printf("%lld\n",factor[0]*factor[1]); } else { printf("%d\n",2); } } return 0;}
- Codeforces 151C(分解因数)
- Codeforces Round #157 (Div. 1)C(因数分解+二分+组合数)
- 分解因数
- 因数分解
- 分解因数
- 因数分解
- 因数分解
- 分解因数
- 百炼-2749-分解因数-C语言-递归算法
- 百炼-2749-分解因数-C语言-递归算法
- 质因数分解 PLUS 因数分解
- 素因数分解
- 因数分解问题
- n!分解质因数、因数
- 因数分解问题
- OpenJudge2749:分解因数
- 分解素因数 1
- 分解素因数 2
- Java面试近一个月的面试总结
- 安装好DELPHI XE10,参照手册简单的创建了一个android app 程序,run的时提示: Android SDK tools are required. Do you want to d
- VMware一些使用心得
- Super Jumping! Jumping! Jumping! HDU
- 一个基于C++的多线程编程实例(CreateThread函数)
- Codeforces 151C(分解因数)
- Apache Mesos Essentials.pdf 英文原版 免费下载
- 神经网络中的关键算法
- 一期回顾之刷数组有感
- HDU P1002 A + B Problem II
- An introduction to smoothing--forcked from matthew-brett
- Aerospike insert、drop、read和emigrate加锁及引用计数流程
- 算法模板——线段树
- 对象扩展