Codeforces Round #651 (Div. 2) C. Number Game (博弈,数学)

题意:对于正整数\(n\),每次可以选择使它变为\(n-1\)或者\(n/t\) (\(n\ mod\ t=0\)且\(t\)为奇数),当\(n=1\)时便不可以再取,问先手赢还是后手赢.
题解:首先特判\(1\)和\(2\)的情况,然后显然如果\(n\)是奇数,一定是先手赢.
如果\(n\)是偶数,那么我们去找它的奇数因子.
如果没有,那么先手只能减一,后手直接赢.
如果有,那么我们直接将它的所有奇数因子拿走,剩下一个孤零零的偶数给后手,如果这个偶数不是\(2\)的话,先手赢,否则后手赢.
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL; int t;
int n; bool check(int x){
for(int i=2;i<=x/i;++i){
if(x%i==0){
if(i!=2 && x/i!=2){
if(i%2==1 || (x/i)%2==1){
return true;
}
}
}
}
return false;
} int main() {
ios::sync_with_stdio(false);cin.tie(0);
cin>>t;
while(t--){
cin>>n;
if(n==1){
cout<<"FastestFinger"<<endl;
}
else if((n%2==1&&n>1)||n==2){
cout<<"Ashishgup"<<endl;
}
else{
if(check(n)){
cout<<"Ashishgup"<<endl;
}
else{
cout<<"FastestFinger"<<endl;
}
} }
return 0;
}
Codeforces Round #651 (Div. 2) C. Number Game (博弈,数学)的更多相关文章
- Codeforces Round #651 (Div. 2) C. Number Game(数论)
题目链接:https://codeforces.com/contest/1370/problem/C 题意 给出一个正整数 $n$,Ashishgup 和 FastestFinger 依次选择执行以下 ...
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples(数学)
Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a ...
- Codeforces Round #622 (Div. 2) B. Different Rules(数学)
Codeforces Round #622 (Div. 2) B. Different Rules 题意: 你在参加一个比赛,最终按两场分赛的排名之和排名,每场分赛中不存在名次并列,给出参赛人数 n ...
- Codeforces Round #284 (Div. 2)A B C 模拟 数学
A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #651 (Div. 2) A Maximum GCD、B GCD Compression、C Number Game、D Odd-Even Subsequence
A. Maximum GCD 题意: t组输入,然后输入一个n,让你在区间[1,n]之间找出来两个不相等的数a,b.求出来gcd(a,b)(也就是a,b最大公约数).让你求出来最大的gcd(a,b)是 ...
- Codeforces Round #266 (Div. 2) C. Number of Ways
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split ...
- Codeforces Round #651 (Div. 2) A. Maximum GCD(数论)
题目链接:https://codeforces.com/contest/1370/problem/A 题意 有 $n$ 个数大小分别为 $1$ 到 $n$,找出两个数间最大的 $gcd$ . 题解 若 ...
- Codeforces Round #651 (Div. 2) B. GCD Compression(数论)
题目链接:https://codeforces.com/contest/1370/problem/B 题意 给出 $2n$ 个数,选出 $2n - 2$ 个数,使得它们的 $gcd > 1$ . ...
- Codeforces Round #651 (Div. 2) D. Odd-Even Subsequence(二分)
题目链接:https://codeforces.com/contest/1370/problem/D 题意 给出一个含有 $n$ 个数的数组 $a$,从中选出 $k$ 个数组成子序列 $s$,使得 $ ...
随机推荐
- 转载 - Ubuntu源改国内源 与 批量更改ubuntu机器apt源
change_apt_source.sh # !/bin/bash # 备份原来的源文件 cp /etc/apt/sources.list /etc/apt/sources.list.bak # 获取 ...
- ansible 安装和使用
ansible 安装和使用 ## 安装epel 源: rpm -ivh https://dl.fedoraproject.org/pub/e ...
- 十四:SQL注入之类型及提交注入
简要明确参数类型 数字,字符,搜索,json等 简要明确请求方法 GET,POST,COOKIE,REQUEST,HTTP头 其中SQL语句干扰符号:' " % ) } 等,具体查看用法 非 ...
- 【Linux】实现端口转发的rinetd
Linux下端口转发一般都使用iptables来实现,使用iptables可以很容易将TCP和UDP端口从防火墙转发到内部主机上.但是如果需要将流量从专用地址转发到不在您当前网络上的机器上,可尝试另一 ...
- SDUST数据结构 - chap2 线性表
一.判断题: 二.选择题: 三.编程题: 7-1 jmu-ds-顺序表区间元素删除 : 输入样例: 10 5 1 9 10 67 12 8 33 6 2 3 10 输出样例: 1 67 12 33 2 ...
- ctfhub技能树—信息泄露—备份文件下载—bak文件
打开靶机 查看页面信息 继续使用dirsearch进行扫描 python3 dirsearch.py -u http://challenge-d4234042e1d43e96.sandbox.ctfh ...
- CSS居中的常用方式以及优缺点
前言 居中是页面开发中经常遇到的问题. 使用合适的.简单的.兼容性好的居中方式是我们页面仔在整个工作生涯中都要面对的问题. text-align:center 来看这个例子,一张图片和文字进行居中.如 ...
- Language Guide (proto3) | proto3 语言指南(七)更新消息类型
Updating A Message Type - 更新消息类型 如果现有的消息类型不再满足您的所有需要(例如,您希望消息格式有一个额外的字段),但是您仍然希望使用用旧格式创建的代码,不要担心!在不破 ...
- Go语言学习笔记(3)——面向对象编程
把存货赶紧更新一波(捂脸) 1. 类型系统 类型系统,就是说一种编程语言怎么设计的它的类型的体系结构. 比如基础类型啊,复合类型啊,一些可以指向任意对象的类型啊,以及类型的语义,面向对象的特性,接口, ...
- isEmpty isBlank 区别
Sring test=" "; 这个 isblank 返回 true 但是 isEmpty 返回 false 所以: 一般用 isBlank 就可以了 ,是逐个字符检查 pu ...