原题面:https://codeforces.com/contest/1243/problem/C

题目大意:给定数字n,有n个方块,第i个和第j个之间的距离(abs(i-j))如果是n的因子,那么第i块和第j块颜色相同,统计一下最后有多少种不同颜色的方块。

输入描述:输入一个正整数n。

输出描述:输出一共有多少种颜色不同的方块。

输入样例1:


输出样例1:


输入样例2:


输出样例2:


分析:这个题猜了好几个结论才过了,我把它想的有点抽象,应该理解求最小循环节问题才对。这样就只用对n的所有因子求最小公因数,就是最小循环节。

代码:

def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b) n = input()
n = int(n)
i = 2
ans = n
while i * i <= n:
if n % i == 0:
ans = gcd(ans, i)
ans = gcd(ans, n//i)
i += 1
print(ans)

Codeforces1243C Tile Painting的更多相关文章

  1. Codeforces Round #599 (Div. 1) A. Tile Painting 数论

    C. Tile Painting Ujan has been lazy lately, but now has decided to bring his yard to good shape. Fir ...

  2. Codeforces Round #599 (Div. 2) C. Tile Painting

    Ujan has been lazy lately, but now has decided to bring his yard to good shape. First, he decided to ...

  3. A Tile Painting(循环节)

    Ujan has been lazy lately, but now has decided to bring his yard to good shape. First, he decided to ...

  4. 【CF1243C】 Tile Painting【思维】

    题意:给定长度为n的方块,要求染色,需要满足:当|j-i|>1且n%|j-i|==0时,两格颜色相同,求做多可以染多少种颜色 题解:求出n的所有质因子 1.若只有一种质因子,则答案为该质因子 2 ...

  5. Codeforces Round #599 (Div. 2) Tile Painting

    题意:就是给你一个n,然后如果  n mod | i - j | == 0  并且 | i - j |>1 的话,那么i 和 j 就是同一种颜色,问你最大有多少种颜色? 思路: 比赛的时候,看到 ...

  6. Zero-input latency scheduler: Scheduler Overhaul

    Scheduler Overhaul, with contributions from rbyers, sadrul, rjkroege, sievers, epenner, skyostil, br ...

  7. Codeforces Round #599 (Div. 2)

    久违的写篇博客吧 A. Maximum Square 题目链接:https://codeforces.com/contest/1243/problem/A 题意: 给定n个栅栏,对这n个栅栏进行任意排 ...

  8. Painting The Wall 期望DP Codeforces 398_B

    B. Painting The Wall time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. 一些DevExpress控件概况!!!!主要DocumentManager.WindowsUIView.Tile

    WinForms Controls The links below provide comprehensive information on using DevExpress WinForms pro ...

随机推荐

  1. text-align:center;在ie7下,父级加上会让block状态的子元素居中。

    text-align:center:在ie7下,父级加上会让block状态的子元素居中.ie8以上不会.

  2. get your sqlserver database back by using EMC NW NMM

    Dear all Yes ~ We can backup our sqlserver by EMC NW NMM. That is true and NW is a very very powerfu ...

  3. 哈希表,Java中的hashCode

    哈希表: 将我们所需的键通过哈希函数转换索引,然后存储在一个数组中. 哈希表是时间和空间之间的平衡,体现空间换时间的算法思想(联想到预加载,缓存等,有时候多存储,预处理缓存一些东西,带来时间复杂度的改 ...

  4. mysql遇到java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed

    在连接数据库的url中,加上allowPublicKeyRetrieval=true from:https://blog.csdn.net/Gushiyuta/article/details/9323 ...

  5. Iterator作用

    前言 下面的内容是我从百度知道拷贝出来的,也就不在贴出链接了.我总结下就是迭代器在集合中使用,用户不需要关心具体集合实现的是如何遍历(不暴露细节),按照迭代器的方式遍历. 作用 Iterator模式是 ...

  6. 「AMPPZ2014」The Prices

    传送门 Luogu团队题链接 解题思路 看到 \(m\) 这么小,马上想到状压 \(\text{DP}\). 设 \(dp[i][j]\) 表示在前 \(i\) 家商店中已买商品的状态为 \(j\) ...

  7. IOS 常用功能代码

    1. 关闭/隐藏键盘 resignFirstResponder 响应view的方法 -(IBAction)fname:(id)sender{ [sender resignFirstResponder] ...

  8. Windows Mysql Server重启, log-bin路径配置

    Windows Mysql Server重启, log-bin路径配置 分类: mysql数据库2014-03-16 14:49 1313人阅读 评论(0) 收藏 举报 Mysqlmysql serv ...

  9. 每个项目中,你必须知道的11个Java第三方类库。

    Java第三方library ecosystem是一个很广阔的范畴.不久前有人撰文:每个项目中,你必须知道的11个Java第三方类库. 单元测试 1.DBUnit DBunit是一个基于junit扩展 ...

  10. 什么叫github

    git remote add origin https://github.com/huiwangui/git-demo.git:表示在本地仓库关联远程仓库(https://github.com/hui ...