题意:就是给你一个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. 运行jar包中的main方法

    java -classpath jar包名.jar 包名.类名

  2. PHPExcel方法总结

    下面是总结的几个使用方法include 'PHPExcel.php';include 'PHPExcel/Writer/Excel2007.php';//或者include 'PHPExcel/Wri ...

  3. Java线程池 ThreadPoolExecutor类

    什么是线程池? java线程池是将大量的线程集中管理的类, 包括对线程的创建, 资源的管理, 线程生命周期的管理. 当系统中存在大量的异步任务的时候就考虑使用java线程池管理所有的线程, 从而减少系 ...

  4. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-question-sign

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...

  5. Nature

    1.主干 (1)<河图+洛书>:启发伏羲作八卦. (2)<三坟+五典>:失传:伏羲.神农.轩辕.少昊.颛顼.帝喾.唐尧.虞舜. (3)<八索+九丘>:失传:八卦之书 ...

  6. P1048 数字加密

    P1048 数字加密 转跳点:

  7. redis : Can't save in background: fork: Cannot allocate memory

    redis : Can't save in background: fork: Cannot allocate memory JAVA程序报错信息: MISCONF Redis is configur ...

  8. 云时代架构阅读笔记二——Java性能优化(二)

    承接上文Java性能优化(一)https://www.cnblogs.com/guo-xu/p/11019267.html 4)尽量确定StringBuffer的容量 在说和这个标题相关之前,先说一下 ...

  9. Enum应用

    public enum ZDJGJD { YSZ("01",0.3,"取得预售许可"),JGFD("02",0.6,"单位结构封顶 ...

  10. Java的Regex --正则表达式

    一.概述 正则表达式通常被用来对字符串提供范围性的校验.替换那些符合某个模式(规则)的文本. 正则表达式所对应的类Pattern,所有的正则表达式都是在这个类下创建的.Pattern类用于创建一个正则 ...