题意:就是给你一个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的更多相关文章

  1. 贪心 Codeforces Round #173 (Div. 2) B. Painting Eggs

    题目传送门 /* 题意:给出一种方案使得abs (A - G) <= 500,否则输出-1 贪心:每次选取使他们相差最小的,然而并没有-1:) */ #include <cstdio> ...

  2. 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 ...

  3. 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 ...

  4. Codeforces Round #599 (Div. 2)

    久违的写篇博客吧 A. Maximum Square 题目链接:https://codeforces.com/contest/1243/problem/A 题意: 给定n个栅栏,对这n个栅栏进行任意排 ...

  5. 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 ...

  6. 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 ...

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

                                                                                   D. Painting The Wall ...

  8. Codeforces Round #353 (Div. 2)Restoring Painting

    Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was sto ...

  9. 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 ...

随机推荐

  1. DRF项目之自定义分页器

    在项目中,我们多需要自定义分页器. 代码实现: class PageNum(PageNumberPagination): '''自定义分页器''' # 每页显示个数 page_size = 10 pa ...

  2. 055、Java中使用for循环输出乘法口诀表

    01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...

  3. 051、Java中使用while循环实现1~100的累加

    01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...

  4. 二次urldecode注入

    原理大多数web程序都会对输入字符进行转换,例如addslashes(),mysql_real_escape_string(),mysql_escape_string(),也就是对单引号',双引号&q ...

  5. POJ 3090 欧拉函数

    求一个平面内可见的点,其实就是坐标互质即可,很容易看出来或者证明 所以求对应的欧拉函数即可 #include <iostream> #include <cstdio> #inc ...

  6. POJ 3321:Apple Tree 树状数组

    Apple Tree Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 22131   Accepted: 6715 Descr ...

  7. 51nod 1352:集合计数

    1352 集合计数 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题  收藏  关注 给出N个固定集合{1,N},{2,N-1},{3,N-2},...,{N-1,2 ...

  8. 从PC厂商狠抓粉丝经济看,春天将至?

    10月中旬,市场研究机构IDC发布的全球三季度PC出货量报告显示,第三季度全球个人电脑出货量总计6740万台,比去年同期下降0.9%.似乎这一数据的发布,依旧在证明着PC市场的颓势.但在这样的大背景下 ...

  9. 官网英文版学习——RabbitMQ学习笔记(五)Publish/Subscribe

    发布/订阅模式:把一个消息发送给多个消费者. 前几篇文章的思想是,我们好像看到了生产者将消息直接发送给queue,然后消费者也从queue中进行消费.其实并非如此,RabbitMQ中的消息传递模型的核 ...

  10. R 读取excel的方法

    1.加载 readxl 包,利用 reade_excel() 函数 install.packages("readxl") library(readxl) data = read_e ...