前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CodeForces - 1245A Good ol' Numbers Coloring (思维)

CodeForces - 1245A Good ol' Numbers Coloring (思维)

作者头像
风骨散人Chiam
发布2020-10-28 11:30:09
3960
发布2020-10-28 11:30:09
举报
文章被收录于专栏:CSDN旧文

Codeforces Round #597 (Div. 2

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

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/11/06 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档