原题面: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. Python学习第十课——文件的基本操作

    文件基本操作 文件读操作 #读出路径下的测试.txt文件 f = open('测试.txt', encoding='utf-8') # 打开要读文件 data = f.read() # 读取内容 pr ...

  2. Spark教程——(7)编写spark-sql程序读取HBase定时生成报表

    plugin划红线报错: maven-scala-plugin maven-shade-plugin 查找Maven仓库,发现一个没有jar包,一个jar包无法解压缩打开,删除Maven中坏的jar包 ...

  3. TensorFlow基础二(Shape)

    首先说明tf中tensor有两种shape,分别为static (inferred) shape和dynamic (true) shape,其中static shape用于构建图,由创建这个tenso ...

  4. 工作脚本拆分xml文并重定向数据

    sed -n '/<N/p' CM-ENB-SRVIDENTIFYBASEBSRTDD-2C-ALLV2.9.0-20191209020003.xml.gz.xml|awk -F"&g ...

  5. 关于eclipse项目右键没有project facets的解决方法遇到的问题

    [ 关于eclipse项目右键没有project facets的解决方法] [创建maven项目生成WebRoot目录,web.xml文件,以及修改编译路径classess的解决办法,以及解决找不到或 ...

  6. Kafka 启动报错java.io.IOException: Can't resolve address.

    阿里云上 部署Kafka 启动报错java.io.IOException: Can't resolve address. 本地调试的,报错 需要在本地添加阿里云主机的 host 映射   linux ...

  7. SpringBoot项目中自定义注解的使用

    1.定义注解接口 @Documented @Retention(RUNTIME) @Target(METHOD) public @interface MyLog {    String value() ...

  8. Eclipse传递main函数参数

    在项目上右击 Run As->Run Configurations...->Arguments->在Program arguments:的文本框中输入你要传入的参数,若有几个参数则在 ...

  9. Numpy 为运算

    Numpy “bitwise_” 开头的函数是位运算函数: Numpy 位运算包括以下几个函数: 函数 描述  bitwise_and  对数组元素执行位与操作  bitwise_or 对数组元素执行 ...

  10. Metric类型

    Metric类型 在上一小节中我们带领读者了解了Prometheus的底层数据模型,在Prometheus的存储实现上所有的监控样本都是以time-series的形式保存在Prometheus内存的T ...