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 paint the path from his house to the gate.
The path consists of nn consecutive tiles, numbered from 11 to nn. Ujan will paint each tile in some color. He will consider the path aesthetic if for any two different tiles with numbers ii and jj, such that |j−i||j−i| is a divisor of nn greater than 11, they have the same color. Formally, the colors of two tiles with numbers ii and jj should be the same if |i−j|>1|i−j|>1 and nmod|i−j|=0nmod|i−j|=0 (where xmodyxmody is the remainder when dividing xx by yy).
Ujan wants to brighten up space. What is the maximum number of different colors that Ujan can use, so that the path is aesthetic?
The first line of input contains a single integer nn (1≤n≤10121≤n≤1012), the length of the path.
Output a single integer, the maximum possible number of colors that the path can be painted in.
4
2
5
5
In the first sample, two colors is the maximum number. Tiles 11 and 33 should have the same color since 4mod|3−1|=04mod|3−1|=0. Also, tiles 22and 44 should have the same color since 4mod|4−2|=04mod|4−2|=0.
In the second sample, all five colors can be used.
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n;cin>>n;
int flag = ;
long long num = n;
for(long long i=;i*i<=n;i++){
if(n%i==){
num=__gcd(num,i);
num=__gcd(num,n/i);
}
}
cout<<num<<endl;
}
//求除1以外所以因子的最大公约数
/*我们枚举n的所有的因子 a[1],a[2],a[3]....a[x]。
翻译过来就是我们每a[1]个,都得相同;每a[2]个都得相同;....;每a[x]个都得相同。
那么实际上这个东西的循环节就等于他们的最小公倍数。
那么最多个颜色就是n/lcm,实际上就是gcd。因为gcd x lcm = n */
Codeforces Round #599 (Div. 2) C. Tile Painting的更多相关文章
- 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 ...
- Codeforces Round #599 (Div. 2) D. 0-1 MST(bfs+set)
Codeforces Round #599 (Div. 2) D. 0-1 MST Description Ujan has a lot of useless stuff in his drawers ...
- Codeforces Round #599 (Div. 2)
久违的写篇博客吧 A. Maximum Square 题目链接:https://codeforces.com/contest/1243/problem/A 题意: 给定n个栅栏,对这n个栅栏进行任意排 ...
- Codeforces Round #599 (Div. 2) Tile Painting
题意:就是给你一个n,然后如果 n mod | i - j | == 0 并且 | i - j |>1 的话,那么i 和 j 就是同一种颜色,问你最大有多少种颜色? 思路: 比赛的时候,看到 ...
- Codeforces Round #353 (Div. 2) B. Restoring Painting 水题
B. Restoring Painting 题目连接: http://www.codeforces.com/contest/675/problem/B Description Vasya works ...
- Codeforces Round #461 (Div. 2) C. Cave Painting
C. Cave Painting time limit per test 1 second memory limit per test 256 megabytes Problem Descriptio ...
- Codeforces Round #599 (Div. 2)D 边很多的只有0和1的MST
题:https://codeforces.com/contest/1243/problem/D 分析:找全部可以用边权为0的点连起来的全部块 然后这些块之间相连肯定得通过边权为1的边进行连接 所以答案 ...
- Codeforces Round #599 (Div. 2) E. Sum Balance
这题写起来真的有点麻烦,按照官方题解的写法 先建图,然后求强连通分量,然后判断掉不符合条件的换 最后做dp转移即可 虽然看起来复杂度很高,但是n只有15,所以问题不大 #include <ios ...
- Codeforces Round #599 (Div. 1) C. Sum Balance 图论 dp
C. Sum Balance Ujan has a lot of numbers in his boxes. He likes order and balance, so he decided to ...
随机推荐
- C++-HDU3400-Line belt[三分]
将军饮马问题的升级版 二维平面中要从A到D,给出两条线段AB,CD,分别在线段AB,CD,以及空白处的速度为P,Q,R 求最少用时 由于最优位置满足“凸性”,且两条线段可以等价,所以可以采取三分答案迭 ...
- 百度网盘无vip高速下载的方法
我拿的是谷歌浏览器做实验 首先下载一个可以改user-agent的插件 我chorm里面下载的是User-Agent Switcher for Chrome插件 将百度网盘的url地址中的baidu. ...
- TCL常用命令
1.删除文件 file delete A file delete -force A 2.建立文件夹 file mkdir A file mkdir A/A 3.判断文件夹是否存在 file exist ...
- loj6277 数列分块入门题1
裸题分块. #include <bits/stdc++.h> using namespace std; ],b[],n,m,t1,t2,t3,t4,sq; int main(){ ios: ...
- Selenium3+python自动化013-操作浏览器的Cookie
为什么要用Cookie?在测试多个页面时候可绕过验证码输入,直接添加cookie,也可以在添加唯一标识时候使用. 一.操作浏览器的Cookie 1.1.验证码的处理方式 说明:WebDriver类库中 ...
- 用MyEclipse远程debug
第一步 编辑 tomcat下的文件startup.sh文件,我的路径是 /root/apache-tomcat-6.0.24/bin/startup.sh 命令:vim startup.sh将decl ...
- ZJOI2006 书架 lg2596
题面见https://www.luogu.org/problemnew/show/P2596 题面就是描述了一个书柜从上到下放着书,可以看作一个序列,每个数的序号为它在从上向下数第几本 一开始建树偷了 ...
- 将本地文件git到远程github仓库
使用git管理项目是开发人员必备的技能,下面就介绍如何使用git将本地文件管理并且同步到github上面. 小白可以参考 创建SSH-key并且在github中添加认证 在本地用户的.ssh文件下面生 ...
- RN开发-Linux开发环境搭建(Ubuntu 12.04)
1.首先安装JDK 2.安装Android开发环境 3.安装node.js 3.1 官网下载 : node-v6.9.1-linux-x64 3.2 添加环境变量 sudo vi /etc/profi ...
- STL-C - 稳定排序
C - 稳定排序 大家都知道,快速排序是不稳定的排序方法.如果对于数组中出现的任意a[i],a[j](i<j),其中a[i]==a[j],在进行排序以后a[i]一定出现在a[j]之前,则认为该排 ...