ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Game

2021-01-16 19:00:02  阅读:230  来源: 互联网

标签:cnt Johnson int Game Nancy 操作 include


链接:https://ac.nowcoder.com/acm/contest/11424/G
来源:牛客网

题目描述
Nancy喜欢博弈!
Johnson和Nancy得到了一个神奇的多重集合,仅包含一个正整数n,两个人轮流进行操作。
一次操作可以将集合中一个数字分解为它的任意两个非1的因数,并加入集合中。
他们想知道,在Johnson和Nancy绝顶聪明的情况下,如果Nancy先手进行操作,最后谁没有办法继续操作了呢?
输入描述:
第一行:一个整数n。
数据满足:1 \leq n \leq 957181≤n≤95718。
输出描述:
共一行:一个字符串,表示最后谁(Johnson或者Nancy)无法进行操作。
示例1
输入
复制
4
输出
复制
Johnson

可操作次数,就是n的质因数个数-1。比如8=222,3个质因数,可进行两次分解操作,再如40=222*5,4个质因数,3次分解操作。

除此之外,注意n=1时为特例,0次分解操作。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <map>
#include <unordered_map>
#include <vector>
#include <cmath>
#include <ext/rope>
#include <bits/stdc++.h> 

using namespace std;

#define gt(x) x = read()
#define int long long
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

const int mod = 20010905;
const int PP = 131;

inline int read(int out = 0)
{
    char c;
    while((c=getchar()) < 48 || c > 57);
    while(c >= 48 && c <= 57) out=out*10+c-48,c=getchar();
    return out; 
}

const int N = 1e5 + 10;
const int M = 1e6 + 10;


signed main(){
	int n;
	gt(n);
	
	if (n == 1)    cout << "Nancy" << endl;
	else{
        int cnt = 0;
        for (int i = 2; i <= n; i ++){
            while(n % i == 0)  n /= i, cnt ++;
        }
        cnt --;
        if (cnt & 1)    cout << "Johnson" << endl;
        else cout << "Nancy" << endl;
    }
	
	return 0;
}

标签:cnt,Johnson,int,Game,Nancy,操作,include
来源: https://blog.csdn.net/qq_45772483/article/details/112721234

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有