zoukankan      html  css  js  c++  java
  • 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 |ji||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 |ij|>1|i−j|>1 and nmod|ij|=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?

    Input

    The first line of input contains a single integer nn (1n10121≤n≤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
    Copy
    4
    
    output
    Copy
    2
    
    input
    Copy
    5
    
    output
    Copy
    5
    
    Note

    In the first sample, two colors is the maximum number. Tiles 11 and 33 should have the same color since 4mod|31|=04mod|3−1|=0. Also, tiles 22and 44 should have the same color since 4mod|42|=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 = 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;
    }
    //求除1以外所以因子的最大公约数 
    /*我们枚举n的所有的因子 a[1],a[2],a[3]....a[x]。
    翻译过来就是我们每a[1]个,都得相同;每a[2]个都得相同;....;每a[x]个都得相同。
    那么实际上这个东西的循环节就等于他们的最小公倍数。
    那么最多个颜色就是n/lcm,实际上就是gcd。因为gcd x lcm = n  */ 
  • 相关阅读:
    unity xcode debug 学习
    Amplify Shader Editor 学习
    Unity Quality Setting 学习
    Unity3D Distortion 学习
    【原】博客园第三方客户端-i博客园App开源
    【AR实验室】mulberryAR:并行提取ORB特征
    【AR实验室】mulberryAR :添加连续图像作为输入
    【原】C++11并行计算 — 数组求和
    【AR实验室】mulberryAR : ORBSLAM2+VVSION
    【AR实验室】OpenGL ES绘制相机(OpenGL ES 1.0版本)
  • 原文地址:https://www.cnblogs.com/QingyuYYYYY/p/11829336.html
Copyright © 2011-2022 走看看