Dreamoon and Sets

CodeForces - 476D

Dreamoon likes to play with sets, integers and  is defined as the largest positive integer that divides both a and b.

Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements sisj from S.

Given k and n, Dreamoon wants to make up n sets of rank k using integers from 1 to msuch that no integer is used in two different sets (of course you can leave some integers without use). Calculate the minimum m that makes it possible and print one possible solution.

Input

The single line of the input contains two space separated integers nk (1 ≤ n ≤ 10 000, 1 ≤ k ≤ 100).

Output

On the first line print a single integer — the minimal possible m.

On each of the next n lines print four space separated integers representing the i-th set.

Neither the order of the sets nor the order of integers within a set is important. If there are multiple possible solutions with minimal m, print any one of them.

Examples

Input
  1. 1 1
Output
  1. 5
    1 2 3 5
Input
  1. 2 2
Output
  1. 22
    2 4 6 22
    14 18 10 16

Note

For the first example it's easy to see that set {1, 2, 3, 4} isn't a valid set of rank 1 since .

sol:构造出来的肯定是四个互质的数字*K,对于这四个互质的数字要尽量小,容易构造出这样四个

1 2 3 5

7 8 9 11   (每次加6)

没有比上面更小的了

  1. /*
  2. 输出n组集合,每组4个。对于任意一组中的4个元素,一组内任意2个数的gcd==k
  3. 且n组的所有数字各不相同。要使得n组中最大的数字最小。
  4. */
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7. typedef int ll;
  8. inline ll read()
  9. {
  10. ll s=;
  11. bool f=;
  12. char ch=' ';
  13. while(!isdigit(ch))
  14. {
  15. f|=(ch=='-'); ch=getchar();
  16. }
  17. while(isdigit(ch))
  18. {
  19. s=(s<<)+(s<<)+(ch^); ch=getchar();
  20. }
  21. return (f)?(-s):(s);
  22. }
  23. #define R(x) x=read()
  24. inline void write(ll x)
  25. {
  26. if(x<)
  27. {
  28. putchar('-'); x=-x;
  29. }
  30. if(x<)
  31. {
  32. putchar(x+''); return;
  33. }
  34. write(x/);
  35. putchar((x%)+'');
  36. return;
  37. }
  38. #define W(x) write(x),putchar(' ')
  39. #define Wl(x) write(x),putchar('\n')
  40. int n,K;
  41. int main()
  42. {
  43. int i;
  44. R(n); R(K);
  45. Wl((+(n-)*)*K);
  46. for(i=;i<=n;i++)
  47. {
  48. int oo=((i-)*)*K;
  49. W(K+oo); W(*K+oo); W(*K+oo); Wl(*K+oo);
  50. }
  51. return ;
  52. }
  53. /*
  54. Input
  55. 1 1
  56. Output
  57. 5
  58. 1 2 3 5
  59.  
  60. Input
  61. 2 2
  62. Output
  63. 22
  64. 2 4 6 22
  65. 14 18 10 16
  66. */

codeforces476D的更多相关文章

随机推荐

  1. 开箱即用(out-of-box)的Redis序列号生成器,不用再写任何代码,你值得拥有

      先看整体效果 把简单的东西“傻瓜化”是软件开发追求的目标之一.请看下图: 左边是在 application.yml 里配置了3个生成器,右边可以直接注入到代码中使用,注意,不用写任何代码.这酸爽. ...

  2. 【Vuex】vuex基本介绍与使用

    Vuex是什么? 官方解释: Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式.它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化.Vuex 也集 ...

  3. 服务器配置java

    先去链接下载jdk or jre(服务器上这个就好) 然后解压 tar 下载的文件,放到/usr/local/java/jdk_xxx下面 -v: 可视化显示进度. Enables verbose m ...

  4. 用VS2017进行移动开发(C#、VB.NET)——Progress控件,Smobiler移动开发

    Progress控件 一.          样式一 我们要实现上图中的效果,需要如下的操作: 从工具栏上的“Smobiler Components”拖动一个Progress控件到窗体界面上 修改Pr ...

  5. Asp.Net Web APi 路由的特点

    在ASP.NET Web API中,路由是基于HTTP协议 GET请求路由到以GET开头的控制器方法,POST请求路由到以POST开头的控制器方法中,GET方法和GetProducts,都能与GET请 ...

  6. JS里charCodeAt()和fromCharCode()方法拓展应用:加密与解密

    JS实现客户端的网页加密解密技术,可用作选择性隐蔽展示.当然客户端的加密安全度是不能与服务器相提并论,肯定不能用于密码这类内容的加密,但对于一般级别的内容用作展示已经够了. JS加密与解密的解决方案有 ...

  7. oracle学习笔记(七) 预编译Statement介绍与使用

    预编译Statement优点 执行效率高 由于预编译语句使用占位符 "?",在执行SQL之前语句会被先发送到Oracle服务器进行语法检查和编译等工作,并将SQL语句加入到Orac ...

  8. javaweb中上传视频,并且播放,用上传视频信息为例

    1.上传视频信息的jsp页面uploadVideo.jsp <body background="image/bk_hero.jpg"><div id=" ...

  9. transform旋转,平移,缩放,扭曲 斜切

    transform  改变rotate 旋转translate  位移scale 缩放 skew  斜切变形 记得兼容性:-webkit-   -moz-    -ms-     -o- transf ...

  10. javascript面向对象习题答案

    第二章 1.如果我们在控制台中执行下列语句,结果分别是什么?为什么? var a; typeof a; undefined > var s = '1s'; s++; NaN > !!&qu ...