CodeForces - 1245A Good ol' Numbers Coloring (思维)
| Codeforces Round #597 (Div. 2 | 
|---|
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
这就是模拟的辗转相减的求最大公约数的算法。最大公约数是1,就能遍历每一个点,即全是白点,不然就全是黑点。
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#include<vector>
#include<iostream>
using namespace std;
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int x,y;
        cin>>x>>y;
        if(__gcd(x,y)==1) puts("Finite");
        else puts("Infinite");
    }
    return 0;
}
												
											CodeForces - 1245A Good ol' Numbers Coloring (思维)的更多相关文章
- Codeforces Round #597 (Div. 2) A. Good ol' Numbers Coloring
		
链接: https://codeforces.com/contest/1245/problem/A 题意: Consider the set of all nonnegative integers: ...
 - CF1245 A. Good ol' Numbers Coloring(java与gcd)
		
题意:给定数字A和数字B,问是否满足gcd(A,B)==1. 思路:可以直接写函数gcd.也可以用大数自带的gcd功能. 代码1: /* @author nimphy @create 2019-11- ...
 - [codeforces 55]D. Beautiful numbers
		
[codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It ...
 - Codeforces 631 (Div. 2) C. Dreamoon Likes Coloring 思维or构造
		
https://codeforces.com/contest/1330/problem/C 给n个格子染色,有m种颜色,要求最后的所以格子被染色,并且有m种颜色. 染色要求:每种颜色有一个值li,选择 ...
 - Codeforces Round #673 (Div. 2) C. k-Amazing Numbers(思维)
		
题目链接:https://codeforces.com/contest/1417/problem/C 题意 给出一个大小为 $n$ 的数组 $a$,计算当 $k$ 从 $1$ 到 $n$ 取值时在所有 ...
 - Educational Codeforces Round 63 (Rated for Div. 2) B. Game with Telephone Numbers 博弈思维+模拟+贪心思维
		
题意:博弈题面 给出一个数字序列 (>=11) 有两个人任意删除数字 直到 数字只剩下11位 如果删除后的数字串开头是8那么就是第一个赢 否则就是第二个人赢 第一个人先手 数字序列一定是奇 ...
 - Codeforces Round #673 (Div. 2) C. k-Amazing Numbers  (DP,思维)
		
题意:有一组数,分别用长度从\([1,n]\)的区间去取子数组,要求取到的所有子数组中必须有共同的数,如果满足条件数组共同的数中最小的数,否则输出\(-1\). 题解:我们先从后面确定每两个相同数之间 ...
 - Codeforces Round #143 (Div. 2) (ABCD 思维场)
		
题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test: ...
 - Codeforces Round #395 (Div. 2)(A.思维,B,水)
		
A. Taymyr is calling you time limit per test:1 second memory limit per test:256 megabytes input:stan ...
 
随机推荐
- (js描述的)数据结构[集合结构](6)
			
(js描述的)数据结构[集合结构](6) 一.集合结构特点 1.集合中的元素不能重复. 2.集合是无序的. 二.集合的代码实现 function Set() { this.items = {} //1 ...
 - C语言学生管理系统完善版
			
#include<stdio.h>#include<string.h>#include <stdlib.h>#define M 100struct score ...
 - 抽签小程序,妈妈再也不用担心谁洗碗(分配任务)了,so easy
			
背景 今天谁炒菜,谁洗碗,谁买菜...啊,Boss说用抽签吧,于是有了下图 这样存在作弊的问题(记住棍子特征,谁先,谁后抽等等)于是有了这个抽签小程序(当然小程序我一个人控制,我想不想作弊看心情了) ...
 - Python爬虫系列(二):requests基础
			
1.发送请求: import requests # 获取数据#r是一个 response 对象.包含请求返回的内容r = requests.get('https://github.com/timeli ...
 - sql 案例
			
select now();#获取当前系统时间 select now() from dual;#与Oracle兼容 show character set;#产看当前数据库支持的字符集 create da ...
 - 数据结构和算法(Golang实现)(28)查找算法-AVL树
			
AVL树 二叉查找树的树高度影响了查找的效率,需要尽量减小树的高度,AVL树正是这样的树. 一.AVL树介绍 AVL树是一棵严格自平衡的二叉查找树,1962年,发明者Adelson-Velsky和La ...
 - redis list  基本操作
			
写在前面的话 本篇笔记写在笔者刚工作时.如有问题,请指教. 简介 list是链表,redis list的应用场景很多,也是Redis 最重要的数据结构之一,比如微博的关注列表,粉丝列表,消息列表等功能 ...
 - 浅谈Vector
			
浅谈Vector 在之前的文章中,我们已经说过线程不安全的ArrayList和LinkedList,今天我们来讲讲一个线程安全的列表容器,他就是Vector,他的底层和ArrayList一样使用数组来 ...
 - 学习Saleforce | 业内第一份Salesforce学习者数据报告
			
自从自由侠部落这个Salesforce中文学习平台成立以来,我们接触到了越来越多的Salesforce的学习者,由衷感觉到这个学习生态圈愈发蓬勃发展. 为了了解Salesforce学习者的基本情况.现 ...
 - substr和substring之间的区别
			
substr 和 substring都是JS 截取字符串函数,两者用法很相近,下面是两者的语法很示例: substr 方法 返回一个从指定位置开始的指定长度的子字符串.stringvar.substr ...