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. 【原创】使用批处理脚本生成包并自动上传到nuget

    Hello 大家好,我是TANZAME,我们又见面了. NuGet 是什么这里就不再重复啰嗦,园子里一搜一大把.今天要跟大家分享的是,在日常开发过程中如何统一管理我们的包,如何通过批处理脚本生成包并自 ...

  2. 微擎 manifest.xml

    微擎 manifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns= ...

  3. opencv 7 直方图与匹配

    图像直方图概述 直方图的计算与绘制 计算直方图:calcHist()函数 找寻最值:minMaxLoc()函数 示例程序:绘制H-S直方图 #include "opencv2/highgui ...

  4. go语言学习笔记(二)

    整数 有符号整数 int8 int16 int32 int64 无符号整数 uin8 uin16 uin32 uin64 无符号整数 uintptr可以进行运算这点很重要请了解unsafe包,大小不明 ...

  5. Ubuntu 16.04安装ROS Kinetic详细教程 | Tutorial to Install and Configure ROS Kinetic on Ubuntu 16.04

    本文首发于个人博客https://kezunlin.me/post/e2780b93/,欢迎阅读! Tutorial to Install and Configure ROS Kinetic on U ...

  6. node中mysql和短信使用方法(3)

    一.mysql的使用 使用mysql首先得有数据库并且表里面有数据,我创建了数据库newsql,里面Tables有表company等等. company有id,name,other等字段 1.导入my ...

  7. Acquistion Location Confidence for accurate object detection

    Acquistion Location Confidence for accurate object detection 本论文主要是解决一下两个问题: 1.分类得分高的预测框与IOU不匹配,(我猜应 ...

  8. Java面向对象学习目录

    Java面向对象学习目录 以下为面向对象学习目录,有待补充的部分,我还会再后续的学习过程中加以补充与修改~ 一.面向对象编程思想 二.Java类及类中成员 属性 方法 构造器 代码块 内部类 面向对象 ...

  9. JSONPath入门之Snack3篇

    Snack3 for java 一个微型JSON框架 基于jdk8,60kb.有序列化反序列化.解析和转换.支持 Json path 查询. <dependency> <groupI ...

  10. HTML5的一些验证挺方便的

    一些基本的验证都可以很简单的实现,节省了很多繁琐的步骤.