• C. Tile Painting (定理:任意一个合数都能够写成两个质数的乘积) 《Codeforces Round #599 (Div. 2) 》


    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.

     

      优化:判断是都是素数,如果是直接输出 N 就可以了;反之,如果所有大于2的因子的公约数不为 1 ,输出这个公约数,反之,输出 1。

      分析:给定N个连续方块,假如第 k 个格子已经涂色,那么满足 N%abs(i-k)==0 && abs(i-k)>1的也要图和第k个格子一样的颜色,最多能图多少不同的颜色

      Code:任意一个合数都能够写成两个质数的乘积

    #include <bits/stdc++.h>
    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <string>
    #include <cstring>
    #include <cstdlib>
    #include <map>
    #include <vector>
    #include <set>
    #include <queue>
    #include <stack>
    #include <cmath>
    using namespace std;
    #define mem(s,t) memset(s,t,sizeof(s))
    #define pq priority_queue
    #define pb push_back
    #define fi first
    #define se second
    #define ac return 0;
    #define ll long long
    #define cin2(a,n,m)     for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin>>a[i][j];
    #define rep_(n,m)  for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)
    #define rep(n) for(int i=1;i<=n;i++)
    #define test(xxx) cout<<"  Test  " <<" "<<xxx<<endl;
    #define TLE std::ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);   cout.precision(10);
    #define lc now<<1
    #define rc now<<1|1
    #define ls now<<1,l,mid
    #define rs now<<1|1,mid+1,r
    #define half no[now].l+((no[now].r-no[now].l)>>1)
    #define ll long long
    const int mxn = 1e6+5;
    ll n,m,k,ans,cnt,col,i;
    int a[mxn],b[mxn],flag;
    string str,ch ;
    int main()
    {
        cin>>n;
        for(i=2;i*i<=n && i<=n;i++)
        {
            if(!(n%i))
            {
                while(!(n%i)) n/=i;
                if(n>1)
                {
                    cout<<1<<endl;
                    return 0;
                }
                else
                {
                    cout<<i<<endl;
                    return 0;
                }
            }
        }
        cout<<n<<endl;
        return 0;
    }

      分析:给定N个连续方块,假如第 k 个格子已经涂色,那么满足 N%abs(i-k)==0 && abs(i-k)>1的也要图和第k个格子一样的颜色,最多能图多少不同的颜色

      Code:遍历N的所有因子,gcd所有因子,由 lcm = n / gcd 得出要求的答案(有点循环节得意思)。

    #include <bits/stdc++.h>
    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <string>
    #include <cstring>
    #include <cstdlib>
    #include <map>
    #include <vector>
    #include <set>
    #include <queue>
    #include <stack>
    #include <cmath>
    using namespace std;
    #define mem(s,t) memset(s,t,sizeof(s))
    #define pq priority_queue
    #define pb push_back
    #define fi first
    #define se second
    #define ac return 0;
    #define ll long long
    #define cin2(a,n,m)     for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin>>a[i][j];
    #define rep_(n,m)  for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)
    #define rep(n) for(int i=1;i<=n;i++)
    #define test(xxx) cout<<"  Test  " <<" "<<xxx<<endl;
    #define TLE std::ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);   cout.precision(10);
    #define lc now<<1
    #define rc now<<1|1
    #define ls now<<1,l,mid
    #define rs now<<1|1,mid+1,r
    #define half no[now].l+((no[now].r-no[now].l)>>1)
    #define ll long long
    const int mxn = 1e6+5;
    ll n,m,k,ans,cnt,col;
    int a[mxn],b[mxn],flag;
    string str,ch ;
    int main()
    {
        while(cin>>n)
        {
            ans = n ;
            for(ll i = 2;i*i<=n;i++)
            {
                if(!(n%i))
                    ans = __gcd(__gcd(ans,n/i),i);
                if(ans==1)
                    break;
            }
            cout<<ans<<endl;
        }
        return 0;
    }
    所遇皆星河
  • 相关阅读:
    微软开源Counterfit,用于AI系统安全测试的自动化工具
    吴恩达教你如何读论文:绘制进度表格,论文至少看三遍,还要问自己问题
    前帝国理工金融数学PhD易聪先生的书单
    以机器学习的视角来看时序点过程的最新进展
    文献阅读第一利器:文献笔记法(Literature Notes)
    死磕论文前,不如先找齐一套好用的工具
    后悔没早点认识论文工具大盘点!
    写论文、搞科研、读大学必备的28款软件。
    2-1-HC32F460(华大)+BC260Y(NB-IOT)基本控制篇(自建物联网平台)-基础外设例程-工程模板使用说明
    1-HC32F460(华大)+BC260Y(NB-IOT)基本控制篇(自建物联网平台)--硬件使用说明
  • 原文地址:https://www.cnblogs.com/Shallow-dream/p/11823678.html
Copyright © 2020-2023  润新知