原题面: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. 学习笔记(10)- 智能会话框架rasa

    https://rasa.com/ 阿里用过这个,贝壳也在用这个. 优点: 有中文版本(https://github.com/crownpku/rasa_nlu_chi): 2018年发布,文档多,业 ...

  2. 个人相关API - 行驶方向判断函数

    calculateDrivingDirection(newCoordinates,oldCoordinates){ let o = { direction: '', deviation:null, i ...

  3. Python中property属性的概论和使用方法

    property属性 概念: 定义一个方法但是使用装饰器property,只可以有一个self形参 可以用这样的属性动态的获取属性的值 定义方式(经典类) class Fun(): @property ...

  4. Java编程打开运行exe程序

    String path = "notepad.exe"; //(C:\Program Files\Tencent\QQ\Bin\qq.exe) try { Runtime runt ...

  5. Zabbix在Docker中的应用和监控

    目录 Zabbix在Docker中的应用和监控 一.如何使Zabbix跑在Docker里 1.Docker基础环境配置 2.Docker-compose安装配置 3.启动zabbix server 4 ...

  6. 条款01:视C++为一个语言联邦

    C++由四部分组成: 1)C. 2)Object-Oriented C++.classes,封装,多态,动态绑定(virtual函数) 3)Template C++.泛型编程. 4)STL. 对于内置 ...

  7. java关于hasNext()

    编写一段程序实现如果输入的一组数中含非整数数字,输出数字相加的和以及"attention"字符,如果全部是数字便输出数字的和. 程序1: package mian; import ...

  8. Day2-O-Coloring a Tree CodeForces-902B

    You are given a rooted tree with n vertices. The vertices are numbered from 1 to n, the root is the ...

  9. 关于c++ 感想

    前言 在学校开展了c++的课程,但是不得不说相当乏味. 原因很简单: 1.感觉c++很高级,自己就这智商怎么学的会哦,自己给了自己门槛. 2.c++很难快速的做出一个能够展现的项目,缺乏成就感. 3. ...

  10. 如何借助 Python 俘获女孩子芳心?

    责编 | 刘静 天气降温,感情却升温了? 上午刚到公司,就收到小Q发来的灵魂拷问: ​ ​ “Q仔!要不然下午请个假!我带你去精神科看看!?”我实在忍不了,脱口而出. 话音未落,前排的运营小花回头看向 ...