zoukankan      html  css  js  c++  java
  • A. 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 22 and 44 should have the same color since 4mod|42|=04mod|4−2|=0.

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

     递归分解质因数的部分对复杂度有点懵

    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <set>
    #include <queue>
    #include <map>
    #include <sstream>
    #include <cstdio>
    #include <cstring>
    #include <numeric>
    #include <cmath>
    #include <iomanip>
    #include <deque>
    #include <bitset>
    #include <unordered_set>
    #include <unordered_map>
    #define ll              long long
    #define PII             pair<int, int>
    #define rep(i,a,b)      for(int  i=a;i<=b;i++)
    #define dec(i,a,b)      for(int  i=a;i>=b;i--)
    using namespace std;
    int dir[4][2] = { { 0,1 } ,{ 0,-1 },{ 1,0 },{ -1,0 } };
    const long long INF = 0x7f7f7f7f7f7f7f7f;
    const int inf = 0x3f3f3f3f;
    const double pi = 3.14159265358979323846;
    const double eps = 1e-6;
    const int mod = 998244353;
    const int N = 1e6 + 5;
    //if(x<0 || x>=r || y<0 || y>=c)
    
    inline ll read()
    {
        ll x = 0; bool f = true; char c = getchar();
        while (c < '0' || c > '9') { if (c == '-') f = false; c = getchar(); }
        while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
        return f ? x : -x;
    }
    ll gcd(ll m, ll n)
    {
        return n == 0 ? m : gcd(n, m % n);
    }
    ll lcm(ll m, ll n)
    {
        return m * n / gcd(m, n);
    }
    bool isprime(ll x)
    {
        for (int i = 2; i <= sqrt(x); i++)
        {
            if (x % i == 0)
                return 0;
        }
        return 1;
    }
    vector<int> vis(N + 5),pri;
    void sieve()
    {
        for (int i = 2; i < N; i++)
        {
            if (!vis[i])
                pri.push_back(i);
            for (int x : pri)
            {
                if ((ll)i * x > N)
                    break;
                vis[i * x] = 1;
                if (i % x == 0)
                    break;
            }
        }
    }
    ll n,ans,cnt;
    void work(ll now)
    {
        for (int d : pri)
        {
            if ((ll)d * d > now)
                break;
            if (now % d == 0)
            {
                ans = min(ans, (ll)d);
                cnt++;
                while (now % d == 0)
                    now /= d;
                work(now);
                break;
            }
        }
        if (now != 1)
            ans = min(ans, now), cnt++;
    }
    int main()
    {
        sieve();
        cin >> n;
        ans = n;
        work(n);
        if (cnt >= 2)
            cout << 1 << endl;
        else
            cout << ans << endl;
        return 0;
    }
  • 相关阅读:
    ASP.NET Core -- 安装版
    基础知识系列☞各版本下IIS请求处理过程区别
    基础知识系列☞IList ←vs→ List
    005杰信-factory删除数据
    004杰信-关于formSubmit('factorycreate.action','_self')路径的疑惑
    23SpringMvc_各种参数绑定方式-就是<input那种
    003杰信-在jsp页面输入数据,然后在oracle数据库中插入factory数据,当字段允许为空时要特殊处理
    spring+springmvc+mybatis+maven整合
    22SpringMvc_jsp页面上的数据传递到控制器的说明
    002Jsp的内置对象
  • 原文地址:https://www.cnblogs.com/dealer/p/13034798.html
Copyright © 2011-2022 走看看