题解 CF1242A Tile Painting

Posted colazcy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了题解 CF1242A Tile Painting相关的知识,希望对你有一定的参考价值。

题目链接

Sotuion Tile Painting

题目大意:给定一个长为(n)的序列,如果两个位置(i,j)满足(n ; mod ;|i - j| =0 ;and; |i-j| eq 1)的话这两个位置的颜色必须相同,问最多有多少种颜色

同余,中国剩余定理


分析:

假如(n)是一个质数显然答案是(n)

假如(n)可以分解为(n=pq),其中(p,q)互质(也就是说可以找最小质因子(p)),那么答案为(1)

因为对于任意一对位置(i,j)一定存在一个(x in [1,n])使得(x equiv i (mod ;p))并且(x equiv j (mod;q))

证明:考虑(CRT),显然(lcm(p,q) =n),设特解为(x')的话有(x equiv x'(mod;n)),得证

我们跑一遍欧拉筛递归分解即可

`cpp #include <iostream> #include <vector> using namespace std; const int maxn = 1e6 + 100; typedef long long ll; int vis[maxn + 100]; vector<int> pri; inline void sieve(){ for(int i = 2;i < maxn;i++){ if(!vis[i])pri.push_back(i); for(int x : pri){ if((ll)i * x > maxn)break; vis[i * x] = 1; if(i % x == 0)break; } } } ll n,ans,tot; inline void work(ll now){ for(int d : pri){ if((ll)d * d > now)break; if(now % d == 0){ ans = min(ans,(ll)d); tot++; while(now % d == 0)now /= d; work(now); break; } } if(now != 1)ans = min(ans,now),tot++; } int main(){ sieve(); cin >> n; ans = n; work(n); if(tot >= 2)cout << 1 << ‘ ‘; else cout << ans << ‘ ‘; return 0; }

以上是关于题解 CF1242A Tile Painting的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #599 (Div. 2) Tile Painting

codeforces 19/11/06 div2C. Tile Painting

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

CF1198E Rectangle Painting 2

CF1479B Painting the Array

cf 448 C. Painting Fence