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

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

1 2 3 5

7 8 9 11   (每次加6)

没有比上面更小的了

/*
输出n组集合,每组4个。对于任意一组中的4个元素,一组内任意2个数的gcd==k
且n组的所有数字各不相同。要使得n组中最大的数字最小。
*/
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
int n,K;
int main()
{
int i;
R(n); R(K);
Wl((+(n-)*)*K);
for(i=;i<=n;i++)
{
int oo=((i-)*)*K;
W(K+oo); W(*K+oo); W(*K+oo); Wl(*K+oo);
}
return ;
}
/*
Input
1 1
Output
5
1 2 3 5 Input
2 2
Output
22
2 4 6 22
14 18 10 16
*/

codeforces476D的更多相关文章

随机推荐

  1. C#语法——事件,逐渐边缘化的大哥。

    事件是C#的基础之一,学好事件对于了解.NET框架大有好处. 事件最常见的比喻就是订阅,即,如果你订阅了我的博客,那么,当我发布新博客的时候,你就会得到通知. 而这个过程就是事件,或者说是事件运行的轨 ...

  2. 2.5 Cesium视域分析的实现

    Cesium 视域分析 祝愿周末没事,技术继续分享交流,群685834990

  3. arcgis api 3.x for js 入门开发系列十八风向流动图(附源码下载)

    前言 关于本篇功能实现用到的 api 涉及类看不懂的,请参照 esri 官网的 arcgis api 3.x for js:esri 官网 api,里面详细的介绍 arcgis api 3.x 各个类 ...

  4. python自定义pi函数的代码

    下边内容是关于python自定义pi函数的内容. def pi(): # Compute digits of Pi. # Algorithm due to LGLT Meertens. k, a, b ...

  5. 魅族5.0以上设备(亲测有效)激活Xposed框架的流程

    对于喜欢研究手机的哥们来说,大多时候会使用到Xposed框架及种种功能强大的模块,对于5.0以下的系统版本,只要手机能获得ROOT权限,安装和激活Xposed框架是比较简单的,但随着系统版本的持续更新 ...

  6. 码云代码托管平台与TortoiseSVN的使用

    1.到https://gitee.com/进行注册,然后登陆 可以发现可以将项目设为私有 2.下载tortoisesvn,一路next安装即可 3.项目创建 4.下载项目 5.创建文件并提交 6.如何 ...

  7. Python正则表达式很难?一篇文章搞定他,不是我吹!

    1. 正则表达式语法 1.1 字符与字符类 1 特殊字符:.^$?+*{}| 以上特殊字符要想使用字面值,必须使用进行转义 2 字符类 1. 包含在[]中的一个或者多个字符被称为字符类,字符类在匹配时 ...

  8. 基于nginx搭建yum源服务器

      1.首先关闭防护墙或者设置规则通过且关闭selinux 停止firewall systemctl stop firewalld 禁止firewall开机启动 systemctl disable f ...

  9. c语言static关键字的理解

    static 一.概述 在c语言中static恰当的使用能让程序更加完美,细节上的严谨,代码会更好,也更利于程序的维护与扩展. 而static使用灵活,且又有两种完全无关的用法,所以整理总结一下. 二 ...

  10. Fiddler分享

    链接:https://pan.baidu.com/s/162YmGb7-aUZ6xDf8eRfgpw  密码:j6er