D. Dreamoon and Sets
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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

Given k and n, Dreamoon wants to make up n sets
of rank k using integers from 1 to m such
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.

Sample test(s)
input
1 1
output
5
1 2 3 5
input
2 2
output
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 .

构造。当k等于1时,推几组数据。比如1,2,3,5;7,8,9,11;13,14,15,17。19,20,21,23;25,26,27,29。就会发现是以6为周期,而对每一个周期内的数乘以k就会使周期内的数两两的最大公约数为k。



代码:

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int n, k;
scanf("%d %d", &n, &k);
int a = 1, b = 2, c = 3, d = 5;
printf("%d\n", (d * k + 6 * k * (n- 1)));
a*=k;
b*=k;
c*=k;
d*=k;
for(int i = 0; i < n; i++)
{
printf("%d %d %d %d\n",a, b, c, d);
a += 6 * k;
b += 6 * k;
c += 6 * k;
d += 6 * k;
}
}



最新文章

  1. 浅谈SQL Server中的三种物理连接操作
  2. C# 指定Webbrowser控件所用IE内核版本
  3. Hadoop日记Day18---MapReduce排序分组
  4. 浏览器何时发送一个Option请求
  5. Javascript 笔记与总结(2-9)获取运行时的 style 对象
  6. PAT乙级 1001. 害死人不偿命的(3n+1)猜想 (15)
  7. C++-不要在构造和析构函数中调用虚函数
  8. PB学习笔记(一)
  9. classic asp中使用ADODB.Command防止sql injection
  10. Gulp前端构建工具
  11. 我对CSS中的BFC的理解
  12. linux重要的守护进程
  13. 面向对象_06【抽象类:abstract、接口:interface、实现:implements】
  14. 关于CheckStyle在eclipse出现的问题
  15. 移动端js调试工具:eruda
  16. Python3 Tcp未发送/接收完数据即被RST处理办法
  17. JavaScript知识点总结[部分]
  18. for循环的字节码
  19. webSocket协议与Socket的区别
  20. USB gadget学习笔记

热门文章

  1. ln---创建链接
  2. Win10+TensorFlow-gpu pip方式安装,anaconda方式安装
  3. 八 rowkey设计 几种方法
  4. 为OLED屏添加GUI支持3:字库
  5. CountDownLatch &amp;amp; CyclicBarrier源代码实现解析
  6. Android开发之Volley网络通信框架
  7. SQLite: sqlite_master(转)
  8. SCOPE_IDENTITY()和 SELECT @@IDENTITY 的用法
  9. [Chromium文档转载,第003章]Proposal: Mojo Synchronous Methods
  10. R学习:《R语言数据分析与挖掘实战》PDF代码