Description

Alice and Bob are in their class doing drills on multiplication and division. They quickly get bored and instead decide to play a game they invented.

The game starts with a target integer N≥2N≥2 , and an integer M=1M=1. Alice and Bob take alternate turns. At each turn, the player chooses a prime divisor p of N, and multiply M by p. If the player’s move makes the value of M equal to the target N, the player wins. If M>NM>N , the game is a tie. Assuming that both players play optimally, who (if any) is going to win?

Input

The first line of input contains T(1≤T≤10000)T(1≤T≤10000) , the number of cases to follow. Each of the next T lines describe a case. Each case is specified by N(2≤N≤231−1)N(2≤N≤231−1) followed by the name of the player making the first turn. The name is either Alice or Bob.

Output

For each case, print the name of the winner (Alice or Bob) assuming optimal play, or tie if there is no winner.

Sample Input

10
10 Alice
20 Bob
30 Alice
40 Bob
50 Alice
60 Bob
70 Alice
80 Bob
90 Alice
100 Bob

Sample Output

Bob
Bob
tie
tie
Alice
tie
tie
tie
tie
Alice

Hint

博弈论;质因数分为 一种,两种,和多种,多种必平局,一种时,该质因数数量为奇数时,第一个人胜,偶数则第二个人胜;

两种时,若两种数量相同,则第二个人胜,若相差一个,则第一个胜,否则平局。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<cstring>
using namespace std;
const int mod = 1e9+7;
typedef long long ll;
const int maxn = 1e5+100;
int prime[maxn+10];
bool vis[maxn];
ll cnt;
void judge(int n)
{
cnt=0;
vis[1]=true;
ll i,j;
for(i=2; i<=n; i++)
{
if(!vis[i])
{
prime[cnt++]=i;
}
for(j=0; j<cnt && i*prime[j] <= n; j++)
{
vis[i*prime[j]]=true;
if(i%prime[j]==0) break;
}
}
} int main()
{
judge(maxn);
int T;
cin>>T;
while(T--)
{
ll n;
string ss;
cin>>n>>ss;
int ret = 0;
vector<int> v;
for(int i=0; i<cnt; i++)
{
if(n%prime[i]==0)
{
ret++;
int tmp=0;
while(n%prime[i]==0)
{
n/=prime[i];
tmp++;
}
v.push_back(tmp);
}
if(ret>=3) break;
}
if(n>1)
{
ret++;
v.push_back(1);
}
if(ret>=3) cout<<"tie"<<endl;
else if(ret==1)
{
if(v[0]%2==0)
{
if(ss=="Alice") cout<<"Bob"<<endl;
else cout<<"Alice"<<endl;
}
else
{
if(ss!="Alice") cout<<"Bob"<<endl;
else cout<<"Alice"<<endl;
}
}
else if(ret==2)
{
if(v[1]==v[0])
{
if(ss=="Alice") cout<<"Bob"<<endl;
else cout<<"Alice"<<endl;
}
else
{
if(abs(v[0]-v[1])==1)
{
if(ss!="Alice") cout<<"Bob"<<endl;
else cout<<"Alice"<<endl;
}
else cout<<"tie"<<endl;
}
}
else cout<<ss<<endl;
}
return 0;
}
/**********************************************************************
Problem: 2115
User: song_hai_lei
Language: C++
Result: AC
Time:1456 ms
Memory:2512 kb
**********************************************************************/

Multiplication Game的更多相关文章

  1. POJ2505 A multiplication game[博弈论]

    A multiplication game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6028   Accepted:  ...

  2. 【数学】Matrix Multiplication

                                 Matrix Multiplication Time Limit: 2000MS   Memory Limit: 65536K Total S ...

  3. hdu 4920 Matrix multiplication bitset优化常数

    Matrix multiplication Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/ ...

  4. 矩阵乘法 --- hdu 4920 : Matrix multiplication

    Matrix multiplication Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/ ...

  5. Booth Multiplication Algorithm [ASM-MIPS]

    A typical implementation Booth's algorithm can be implemented by repeatedly adding (with ordinary un ...

  6. hdu4951 Multiplication table (乘法表的奥秘)

    http://acm.hdu.edu.cn/showproblem.php?pid=4951 2014多校 第八题 1008 2014 Multi-University Training Contes ...

  7. hdu4920 Matrix multiplication 模3矩阵乘法

    hdu4920 Matrix multiplication Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 ...

  8. poj 1651 Multiplication Puzzle (区间dp)

    题目链接:http://poj.org/problem?id=1651 Description The multiplication puzzle is played with a row of ca ...

  9. 矩阵连乘积 ZOJ 1276 Optimal Array Multiplication Sequence

    题目传送门 /* 题意:加上适当的括号,改变计算顺序使得总的计算次数最少 矩阵连乘积问题,DP解决:状态转移方程: dp[i][j] = min (dp[i][k] + dp[k+1][j] + p[ ...

  10. Matrix Chain Multiplication[HDU1082]

    Matrix Chain Multiplication Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

随机推荐

  1. python——切片

    切片 格式:[start : end : step] start:起始索引,从0开始,-1表示结束 end:结束索引 step:步长 # 字符串,列表,元组等都可以支持切片截取的操作# 切片必须依赖于 ...

  2. Python 基础 常用模块

    Python 为我们提供了很多功能强大的模块,今天就主要使用的到的模块进行整理,方便后面来翻阅学习. 一.时间模块 在时间模块中我们重点介绍几种自己常用的功能,主要方便我们按照自己想要的方式获取时间 ...

  3. 单元测试JUnit案例

    被测试模块 package packagedemo; public class Largest { public int minimal(int [] array1) { int index = 0 ...

  4. csp-s2019游记

    11.15D0: 复习 复习 机房里弥漫着颓废的气息,不过也是最后一个下午了 11.16D1: 五点钟爬起来,一边发抖一边去楼下买早饭 虽然平时基本不吃早饭,但考前不行 搭着同学的车去了考点,在车上重 ...

  5. Spring中常用的注解及作用

    @Component(value) 配置类,当使用该注解时,SpringIOC会将这个类自动扫描成一个bean实例 不写的时候,默认是类名,且首字母小写 @ComponentScan 默认是代表进行扫 ...

  6. SqlServer2005 查询 第七讲 order by

    今天我们来讲sql命令中的参数order by的用法 order by order by:可以理解成[以某个字段排序] order by a,b // a和b都按升序 order by a,b des ...

  7. [LC]235题 二叉搜索树的最近公共祖先 (树)(递归)

    ①题目 给定一个二叉搜索树, 找到该树中两个指定节点的最近公共祖先. 百度百科中最近公共祖先的定义为:“对于有根树 T 的两个结点 p.q,最近公共祖先表示为一个结点 x,满足 x 是 p.q 的祖先 ...

  8. API网关在API安全性中的作用

    从单一应用程序切换到微服务时,客户端的行为不能与客户端具有该应用程序的一个入口点的行为相同.简单来说就是微服务上的某一部分功能与单独实现该应用程序时存在不同. 目前在使用微服务时,客户端必须处理微服务 ...

  9. SpringBoot 源码解析 (八)----- Spring Boot 精髓:事务源码解析

    本篇来讲一下SpringBoot是怎么自动开启事务的,我们先来回顾一下以前SSM中是如何使用事务的 SSM使用事务 导入JDBC依赖包 众所周知,凡是需要跟数据库打交道的,基本上都要添加jdbc的依赖 ...

  10. Vue学习笔记:Vuex

    为什么需要Vuex 管理共享状态 解决一份数据在多个组件中试用的困难 系统化的状态管理,区别于小型状态过来 底层设计模式: 全局单例模式 应用场景 适合中大型项目: 小项目反而会因为引入更多概念和框架 ...