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;
}

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

原文地址:https://www.cnblogs.com/YDDDD/p/11797722.html

时间: 2024-10-08 01:18:03

Codeforces Round #597 (Div. 2) A. Good ol' Numbers Coloring的相关文章

Codeforces Round #597 (Div. 2) B. Restricted RPS

链接: https://codeforces.com/contest/1245/problem/B 题意: Let n be a positive integer. Let a,b,c be nonnegative integers such that a+b+c=n. Alice and Bob are gonna play rock-paper-scissors n times. Alice knows the sequences of hands that Bob will play. H

题解Codeforces Round #597 (Div. 2)

A:送分,裸的gcd. 1 #include<stdio.h> 2 #define il inline 3 #define it register int 4 int T,a,b,d; 5 il void gcd(int a,int b){ 6 if(!b){d=a;return;} 7 gcd(b,a%b); 8 } 9 il void fr(int &num){ 10 num=0;char c=getchar();int p=1; 11 while(c<'0'||c>'

Codeforces Round #597 (Div. 2) D. Shichikuji and Power Grid

题意: 二维平面上n个点,每个点可以建厂,也可以与其他点连边,建厂花费为\(c_i\),与j连边花费为\((k_i+k_j)*dis(i,j)\),dis为两点之间的欧式距离,求让每个点都通电的最小花费与方案 思路: 维护使这个点通电的花费的优先队列,一开始先把建厂放进去,然后每次拿出最小花费的点i,再用i去更新与i建路的花费(有点像最小生成树). #include<bits/stdc++.h> #define ll long long #define pii pair<int,int&

codeforces Codeforces Round #597 (Div. 2) D. Shichikuji and Power Grid

#include<bits/stdc++.h> using namespace std ; int n; struct City { int id; long long x,y; //坐标 long long cc,kk; //自建的花费,连线的花费 bool self;//是否建站 int fa;//连线的站 bool operator < (const City & a)const { return cc<a.cc; } } c[2005]; int main() {

Codeforces Round #597 (Div. 2) E. Hyakugoku and Ladders 概率dp

E. Hyakugoku and Ladders Hyakugoku has just retired from being the resident deity of the South Black Snail Temple in order to pursue her dream of becoming a cartoonist. She spent six months in that temple just playing "Cat's Cradle" so now she w

Codeforces Round #597 (Div. 2)D(最小生成树)

/*每个点自己建立一座发电站相当于向超级源点连一条长度为c[i]的边,连电线即为(k[i]+k[j])*两点间曼哈顿距离,跑最小生成树(prim适用于稠密图,kruscal适用于稀疏图)*/ #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;int fa[2007];int x[2007],y[2007];int c[2007],k[2007];long long m[2007][2007];vecto

Codeforces Round #114 (Div. 1) C Wizards and Numbers

题目链接:Wizards and Numbers 题意:有两个数字a, b,假设 a>b,两个玩家进行游戏,有两种操作:1. 令 a=a-b^k,k为正数,且需要保证操作后 a 仍然非负:2. 令 a=a%b.最终有一个人无法操作(存在一个数为0)的时候便输了. 题解:如果只有操作2就是一个辗转相除法,实际上加上了操作1,执行的过程中也一定会出现辗转相除法种每轮的数字情况.所以以辗转相除法的每轮情况作为分段点,讨论其是必胜态还是必败态,首先(t, 0) 一定是必败态,所以其上一层的状态一定是必胜

Codeforces Round #257 (Div. 1) D - Jzzhu and Numbers 容斥原理 + SOS dp

D - Jzzhu and Numbers 这个容斥没想出来... 我好菜啊.. f[ S ] 表示若干个数 & 的值 & S == S得 方案数, 然后用这个去容斥. 求f[ S ] 需要用SOSdp #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i