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 ...
随机推荐
- pymysql 连接池
pymysql连接池 import pymysql from DBUtils.PooledDB import PooledDB, SharedDBConnection ''' 连接池 ''' clas ...
- Python中numpy模块的简单使用
# encoding:utf-8 import numpy as np data1 = np.array([1, 2, 3, 4, 5]) print(data1) data2 = np.array( ...
- Linux下用Bash语言实现输出最大值的功能
题目链接: 题目描述 编写一个程序,输入a.b.c三个值,输出其中最大值. 输入 一行数组,分别为a b c 输出 a b c其中最大的数 样例输入 10 20 30 样例输出 30 复习下Linux ...
- Aspx Ajax 调用 C#函数处理数据
jquery ajax 调用后台函数 var res; $.ajax({ type: "POST", url: "fast_index_overview.aspx/Get ...
- oracle sql 数据库之间导入数据
1.导入别的表 insert into EMPI_IDENTIFY select id,empiid, name||':' ||idcardno,'accidcardno','' from empi_ ...
- Selenium3+python自动化013-自动化数据驱动及模型介绍
一.查看当前运行的浏览等相关信息 driver=webdriver.Chrome() print(driver.capabilities["version"]) #浏览器版本 pr ...
- 3行java代码实现百度站长主动推送
个人博客 地址:http://www.wenhaofan.com/article/push-link-seo 介绍 当网站新增了一个网页之后,此时这个网页是不能够立马被百度收录的,如果想以最快的速度被 ...
- Python读取Excel,日期列读出来是数字的处理
Python读取Excel,里面如果是日期,直接读出来是float类型,无法直接使用. 通过判断读取表格的数据类型ctype,进一步处理. 返回的单元格内容的类型有5种: ctype: 0 empty ...
- AntDesign(React)学习-3 React基础
前面项目已经建起来了,但是没有React基础怎么办,从头学习,这个项目使用的是基于React16.X版本的几种技术集成,那么我们就从网上找一些相关的资料进行研究,我的习惯是用到哪学到哪. 一.先看一些 ...
- 2019-08-07 纪中NOIP模拟B组
T1 [JZOJ1385] 直角三角形 题目描述 二维平面坐标系中有N个位置不同的点. 从N个点选择3个点,问有多少选法使得这3个点形成直角三角形. 数据范围 $3 \leq N \leq 1500$ ...