• Codeforces Round #597 (Div. 2) A. Good ol' Numbers Coloring


    链接:

    https://codeforces.com/contest/1245/problem/A

    题意:

    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).

    思路:

    猜的GCD, 考虑ax+by = gcd(a, b),所以要整除。

    代码:

    #include<bits/stdc++.h>
    using namespace std;
     
    int main()
    {
        ios::sync_with_stdio(false);
        int t;
        cin >> t;
        while(t--)
        {
            int a, b;
            cin >> a >> b;
            if (__gcd(a, b) != 1)
                puts("Infinite");
            else
                puts("Finite");
        }
     
        return 0;
    }
    
  • 相关阅读:
    区间dp体会
    P1083借教室 noip提高组复赛2012
    P2678跳石头体会 noip2015提高组
    tarjan求LCA的体会
    P1006 传纸条
    P1140 相似基因 详解
    UVA1025 城市里的间谍 A Spy in the Metro 题解
    DAG上的动规嵌套矩形问题(含思考题)
    洛谷P1030c++递归求解先序排列
    Test 2019.7.22
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11797722.html
Copyright © 2020-2023  润新知