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.

Examples

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.

題意

現在有長度為n個方格需要染色,現在假設i這個格子染色了,那么所有的j滿足 |j-i|>1 且 n%|j-i| == 0的格子都需要是同一個顏色。

問你最多染多少種顏色

題解

考慮循環節。

我們枚舉n的所有的因子 a[1],a[2],a[3]....a[x]。翻譯過來就是我們每a[1]個,都得相同;每a[2]個都得相同;....;每a[x]個都得相同。

那么實際上這個東西的循環節就等於他們的最小公倍數。那么最多個顏色就是n/lcm,實際上就是gcd。因為gcd x lcm = n

代碼

#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;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM