其他分享
首页 > 其他分享> > C. Ehab and a Special Coloring Problem

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:

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

  

标签:Coloring,const,nn,int,long,ii,integer,Ehab,Problem
来源: https://www.cnblogs.com/YDDDD/p/10972867.html