qscqesze
Published on 2017-09-02 11:31 in 暂未分类 with qscqesze

# 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. First, he decided to paint the path from his house to the gate.

The path consists of 𝑛 consecutive tiles, numbered from 1 to 𝑛. Ujan will paint each tile in some color. He will consider the path aesthetic if for any two different tiles with numbers 𝑖 and 𝑗, such that |𝑗−𝑖| is a divisor of 𝑛 greater than 1, they have the same color. Formally, the colors of two tiles with numbers 𝑖 and 𝑗 should be the same if |𝑖−𝑗|>1 and 𝑛mod|𝑖−𝑗|=0 (where 𝑥mod𝑦 is the remainder when dividing 𝑥 by 𝑦).

Ujan wants to brighten up space. What is the maximum number of different colors that Ujan can use, so that the path is aesthetic?

## Input

The first line of input contains a single integer 𝑛 (1≤𝑛≤1012), the length of the path.

## Output

Output a single integer, the maximum possible number of colors that the path can be painted in.

input
4
output
2
input
5
output
5

## Note

In the first sample, two colors is the maximum number. Tiles 1 and 3 should have the same color since 4mod|3−1|=0. Also, tiles 2 and 4 should have the same color since 4mod|4−2|=0.

In the second sample, all five colors can be used.

## 代码

#include<bits/stdc++.h>
using namespace std;

long long gcd(long long a,long long b){
return b==0?a:gcd(b,a%b);
}
int main(){
long long n;cin>>n;
int flag = 0;
long long num = n;
for(long long i=2;i*i<=n;i++){
if(n%i==0){
num=gcd(num,i);
num=gcd(num,n/i);
}
}
cout<<num<<endl;
}
posted @ 2019-11-07 16:50  qscqesze  阅读(387)  评论(1编辑  收藏