Codeforces Round #599 (Div. 2) Tile Painting

题意:就是给你一个n,然后如果  n mod | i - j | == 0  并且 | i - j |>1 的话,那么i 和 j 就是同一种颜色,问你最大有多少种颜色?

思路: 比赛的时候,看到直接手推,发现有点东西,直接打表找出了规律 —— 如果 n的质因子只有一个,那么总数就是 那个 质因子。其它都为 1。

   今天上课的时候无聊,还是试着推了一下原理。

   1.如果一个数只有一个质因子 x ,那么  n-x 、n-2x、n-3x ……等等全为一种颜色,也就是说每隔 x个就是同种颜色,这样的话就是有x种颜色。

   2.如果一个数有多个质因子,比如有 x、y…………

    那么我们可以推出  n-x 、n-2x、n-3x ……等等全为一种颜色,每隔 x个就是同种颜色

              n-y 、n-2y、n-3y ……等等全为一种颜色,每隔 y个就是同种颜色

    再推 k = gcd(x,y),那么就是每隔k个就是同种颜色,并且由于k是 x和y的最大公因数,所以每隔k个中必然包含 x、y。

    由于x、y都是质数,所以k==1,也就是说每隔 1个就是同种颜色,答案就是 1。

    

原文地址:https://www.cnblogs.com/caibingxu/p/11814063.html

时间: 2024-07-31 05:35:27

Codeforces Round #599 (Div. 2) Tile Painting的相关文章

递归解Codeforces Round #256 (Div. 2)C. Painting Fence

#include<iostream> #include<map> #include<string> #include<cstring> #include<cstdio> #include<cstdlib> #include<cmath> #include<queue> #include<vector> #include<algorithm> using namespace std; in

Codeforces Round #256 (Div. 2) C. Painting Fence

C. Painting Fence Bizon the Champion isn't just attentive, he also is very hardworking. Bizon the Champion decided to paint his old fence his favorite color, orange. The fence is represented as n vertical planks, put in a row. Adjacent planks have no

Codeforces Round #599 (Div. 2) D. 0-1 MST(bfs+set)

Codeforces Round #599 (Div. 2) D. 0-1 MST Description Ujan has a lot of useless stuff in his drawers, a considerable part of which are his math notebooks: it is time to sort them out. This time he found an old dusty graph theory notebook with a descr

Codeforces Round #599 (Div. 2)

A - Maximum Square 题意:给 \(n\) 块宽度为 \(1\) 长度为 \(a_i\) 的木板,把这些木板拼在一起,求最大形成的正方形的边长. 题解:贪心,从大到小排序,然后找第一个满足 \(a_i<i\) 的位置break掉. #include<bits/stdc++.h> using namespace std; typedef long long ll; int n, a[1005]; int main() { #ifdef KisekiPurin freopen

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

Codeforces Round #599 (Div. 2) C. 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

Codeforces Round #256 (Div. 2) C. Painting Fence(分治贪心)

题目链接:http://codeforces.com/problemset/problem/448/C ---------------------------------------------------------------------------------------------------------------------------------------------------------- 欢迎光临天资小屋:http://user.qzone.qq.com/593830943

Codeforces Round #233 (Div. 2)D. Painting The Wall 概率DP

                                                                               D. Painting The Wall User ainta decided to paint a wall. The wall consists of n2 tiles, that are arranged in an n × n table. Some tiles are painted, and the others are not

Codeforces Round #353 (Div. 2)Restoring Painting

Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it. The painting is a