CodeForces - 1245A Good ol' Numbers Coloring

Consider the set of all nonnegative integers: 0,1,2,…. Given two integers a and b (1≤a,b≤104). We paint all the numbers in increasing number first we paint 0, then we paint 1, then 2 and so on.

 

Each number is painted white or black. We paint a number i according to the following rules:

 

if i=0, it is colored white;

if i≥a and i−a is colored white, i is also colored white;

if i≥b and i−b is colored white, i is also colored white;

if i is still not colored white, it is colored black.

In this way, each nonnegative integer gets one of two colors.

 

For example, if a=3, b=5, then the colors of the numbers (in the order from 0) are: white (0), black (1), black (2), white (3), black (4), white (5), white (6), black (7), white (8), white (9), ...

 

Note that:

 

It is possible that there are infinitely many nonnegative integers colored black. For example, if a=10 and b=10, then only 0,10,20,30 and any other nonnegative integers that end in 0 when written in base 10 are white. The other integers are colored black.

It is also possible that there are only finitely many nonnegative integers colored black. For example, when a=1 and b=10, then there is no nonnegative integer colored black at all.

Your task is to determine whether or not the number of nonnegative integers colored black is infinite.

 

If there are infinitely many nonnegative integers colored black, simply print a line containing "Infinite" (without the quotes). Otherwise, print "Finite" (without the quotes).

 

Input

The first line of input contains a single integer t (1≤t≤100) — the number of test cases in the input. Then t lines follow, each line contains two space-separated integers a and b (1≤a,b≤104).

 

Output

For each test case, print one line containing either "Infinite" or "Finite" (without the quotes). Output is case-insensitive (i.e. "infinite", "inFiNite" or "finiTE" are all valid answers).

 

Example

Input

4

10 10

1 10

6 9

7 3

Output

Infinite

Finite

Infinite

Finite

 

 

如果gcd(a,b)==1输出Finite,反之输出Infinite

从0开始,代表的是白色,那么按照题意:

0+a,0+b,2*a,a+b......也是白色,总结起来就是a*x+b*y是白色。

因为a*x+b*y总是能够被gcd(a,b)整除,所以任何不能被gcd(a,b)整除的数都不能用a*x+b*y给表示出来

证明如下:

假设x是一个大于a*b的整数,我们要证明的是大于ab的数都是白色的。

设集合S={x,x-a,x-2*a,....,x-(b-1)*a},在集合S内,如果存在任意一个y∈S,使得y是b的倍数。

假设不存在一个数是b的倍数,我们知道1到b中,除了b是b 的倍数,其他b-1个数都不是b的倍数,那么就有b-1个不同的余数,根据鸽笼原理我们知道,一定存在两个余数相同的数,我们假设这两个数分别是x-t*a和x-r*a,那么x-t*a-(x-r*a)=(r-t)*a一定是b的倍数。

因为gcd(a,b)=1,a不会是b的倍数,r-t<b,所以假设不成立,所以存在是b的倍数的数,故此时代表的是有有限个黑色。

 

#include <bits/stdc++.h>
using namespace std;

int gcd(int a, int b)
{
    while (b)
    {
        a %= b;
        swap(a, b);
    }
    return a;
}

int main()
{
    int t;
    for (cin >> t; t--;)
    
    {
        int a, b;
        cin >> a >> b;
        
        if (gcd(a, b) == 1)
            cout << "Finite" << '\n';
        else
            cout << "Infinite" << '\n';
    }
    
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值