CF Good ol' Numbers Coloring

题目链接:https://codeforces.com/problemset/problem/1245/A

output

standard output

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

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

  • if i=0i=0, it is colored white;
  • if i≥ai≥a and i−ai−a is colored white, ii is also colored white;
  • if i≥bi≥b and i−bi−b is colored white, ii is also colored white;
  • if ii is still not colored white, it is colored black.

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

For example, if a=3a=3, b=5b=5, then the colors of the numbers (in the order from 00) are: white (00), black (11), black (22), white (33), black (44), white (55), white (66), black (77), white (88), white (99), ...

Note that:

  • It is possible that there are infinitely many nonnegative integers colored black. For example, if a=10a=10 and b=10b=10, then only 0,10,20,300,10,20,30 and any other nonnegative integers that end in 00 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=1a=1 and b=10b=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 tt (1≤t≤1001≤t≤100) — the number of test cases in the input. Then tt lines follow, each line contains two space-separated integers aa and bb (1≤a,b≤1041≤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

题意:就是问是否有无限多的黑块。

题解:贝祖定理

           即如果a、b是整数,那么一定存在整数x、y使得ax+by=gcd(a,b)。

这里我们可以利用这个定理,ax+by=k*gcd(a,b),则可以知道若gcd(a, b) == 1是有限多的,其他则为无限多。

代码:

#include
using namespace std;
const int mod = 1e9+7;

int gcd(int a, int b){
    return b == 0 ? a: gcd(b, a % b);
}
int main(){
    int n;
    cin >> n;
    while(n--){
        int a, b;
        cin >> a >> b;
        if(gcd(a, b) == 1)
            cout << "Finite" << endl;
        else
            cout << "Infinite" << endl;
    }
    return 0;
}

 

你可能感兴趣的:(基础题目)