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。
Codeforces Round #599 (Div. 2) Tile Painting的更多相关文章
- 贪心 Codeforces Round #173 (Div. 2) B. Painting Eggs
题目传送门 /* 题意:给出一种方案使得abs (A - G) <= 500,否则输出-1 贪心:每次选取使他们相差最小的,然而并没有-1:) */ #include <cstdio> ...
- 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 ...
- Codeforces Round #599 (Div. 1) A. Tile Painting 数论
C. Tile Painting Ujan has been lazy lately, but now has decided to bring his yard to good shape. Fir ...
- Codeforces Round #599 (Div. 2)
久违的写篇博客吧 A. Maximum Square 题目链接:https://codeforces.com/contest/1243/problem/A 题意: 给定n个栅栏,对这n个栅栏进行任意排 ...
- 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 ...
- Codeforces Round #256 (Div. 2) C. Painting Fence(分治贪心)
题目链接:http://codeforces.com/problemset/problem/448/C C. Painting Fence time limit per test 1 second m ...
- Codeforces Round #233 (Div. 2)D. Painting The Wall 概率DP
D. Painting The Wall ...
- Codeforces Round #353 (Div. 2)Restoring Painting
Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was sto ...
- Codeforces Round #256 (Div. 2) C. Painting Fence 或搜索DP
C. Painting Fence time limit per test 1 second memory limit per test 512 megabytes input standard in ...
随机推荐
- String+、intern()、字符串常量池
字符串连接符 "+"及字符串常量池实验.字符串final属性 结果预览 public class StrTest{ public static void main(String[] ...
- jquery动态选中radio,获取radio选中值
//动态选中radio值,1:表示radio的name 2:表示后台传过来的radio值$(":radio[name='1'][value='" + 2 + "']&qu ...
- 获取选中行中的数据提取并且保存到txt
function getchcount(query: TADOQuery): Integer;var i:integer;begin i:=0; with Query do begin Query.F ...
- Numpy中np.random.randn与np.random.rand的区别,及np.mgrid与np.ogrid的理解
np.random.randn是基于标准正态分布产生的随机数,np.random.rand是基于均匀分布产生的随机数,其值在[0,1). np.mgrid 与np.ogrid的理解及区别:np.mgr ...
- 《机学一》特征工程1 ——文本处理:sklearn抽取、jieba中文分词、TF和IDF抽取
零.机器学习整个实现过程: 一.机器学习数据组成 特征值: 目标值: 二.特征工程和文本特征提取 1.概要: 1.特征工程是什么 2.特征工程的意义:直接影响预测结果 3.scikit-learn库 ...
- Exchange 2003 限制用户向外网发送邮件
在企业系统中,邮件系统起着举足轻重的作用.同时为了符合企业的安全性策略,在Exchange 2003 中,常常需要限制某个用户或组向外网发送邮件,只允许此邮件在内部收发.下面我们以实验的方式来分析在E ...
- SharePreference的使用
SharePreference 一般用于保存偏好设置,比如说我们设置里的条目 sharepreference使用步骤 1.拿到sharepreference //拿到share preference ...
- 151-PHP nl2br函数(二)
<?php $str="h\nt\nm\nl"; //定义一个多处换行的字串 echo "未处理前的输出形式:<br />{$str}"; $ ...
- 1. Centos 安装
安装 Centos 6.9 配置网络 vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 TYPE=Ethernet ONBOOT=yes ...
- windows7配置C++编译环境
将C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin添加到path后,依然不能编译: 新建INCLUDE:C:\Program Fil ...