zoukankan      html  css  js  c++  java
  • Codeforces Round #563 (Div. 2) C. Ehab and a Special Coloring Problem

    链接:https://codeforces.com/contest/1174/problem/C

    题意:

    You're given an integer nn. For every integer ii from 22 to nn, assign a positive integer aiai such that the following conditions hold:

    • For any pair of integers (i,j)(i,j), if ii and jj are coprime, aiajai≠aj.
    • The maximal value of all aiai should be minimized (that is, as small as possible).

    A pair of integers is called coprime if their greatest common divisor is 11.

    思路:

    筛法,把下标为素数的赋予新值,他的倍数再赋予同样的值即可。

    代码:

    #include <bits/stdc++.h>
    
    using namespace std;
    
    typedef long long LL;
    const int MAXN = 3e5 + 10;
    const int MOD = 1e9 + 7;
    int n, m, k, t;
    
    int a[MAXN];
    
    int main()
    {
        cin >> n;
        int cnt = 0, pos = 0;
        for (int i = 2;i <= n;i++)
        {
            if (a[i] != 0)
                continue;
    //        cout << i << endl;
            a[i] = ++pos;
            cnt++;
            int j = 2*i;
            while (j <= n)
            {
                a[j] = pos;
                j += i;
                cnt++;
            }
    //        if (cnt >= n-1)
    //            break;
        }
        for (int i = 2;i <= n;i++)
            cout << a[i] << ' ' ;
        cout << endl;
    
        return 0;
    }
    

      

  • 相关阅读:
    Spring Security配置logout地址
    flex布局
    视口的学习笔记
    box-sizing属性
    css清除浮动
    line-height的理解
    position和float小结
    css居中方法小结
    margin重叠
    浅谈负margin
  • 原文地址:https://www.cnblogs.com/YDDDD/p/10972867.html
Copyright © 2011-2022 走看看