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. webpack初探 - (一)

    什么webpack webpack是一个模块打包器.webpack把模块连同它的依赖一起打包生成包含这些模块的静态资源. 安装 在使用webpack时,建议不要把webpack安装到全局,如果多个项目 ...

  2. SLAM+语音机器人DIY系列:(二)ROS入门——3.在ubuntu16.04中安装ROS kinetic

    摘要 ROS机器人操作系统在机器人应用领域很流行,依托代码开源和模块间协作等特性,给机器人开发者带来了很大的方便.我们的机器人“miiboo”中的大部分程序也采用ROS进行开发,所以本文就重点对ROS ...

  3. sublime text3插件增强侧边栏的功能文件的复制粘贴

    快捷键ctrl + shift +p 输入  install package 回车,调出插件搜索器, 在搜索栏中输入 SideBarEnhancements 回车安装插件. 在侧边栏中的各种操作功能增 ...

  4. java 排序的几篇好文章

    Java8:Lambda表达式增强版Comparator和排序(这篇文章写的不错,各种花式排序) Comparable与Comparator浅析 (基本功)

  5. 调用链监控 CAT 之 URL埋点实践

    URL监控埋点作用 一个http请求来了之后,会自动打点,能够记录每个url的访问情况,并将以此请求后续的调用链路串起来,可以在cat上查看logview 可以在cat Transaction及Eve ...

  6. iOS---------获取当前年份

    NSDate *  senddate=[NSDate date]; NSDateFormatter  *dateformatter=[[NSDateFormatter alloc] init]; [d ...

  7. Java获取图片属性

    BufferdImage bfi = ImageIO.read( new File(“d:/file/img.jpg”) ); //获取图片位深度 Int imgBit = bfi.getColorM ...

  8. DEDE整站动态/静态转换

    方法一:使用DEDE后台的SQL命令行工具 入口:织梦后台-系统-SQL命令行工具 DEDE整站动态化 将所有栏目设置为“使用动态页”: 将所有文档设置为“仅动态”: DEDE整站静态化 将所有栏目设 ...

  9. JS的正则表达式及回文

    function palindrome(str) { str = str.replace(/\s/g,"").replace(/[^a-zA-Z0-9]/g,"" ...

  10. LeetCode算法题-Longest Word in Dictionary(Java实现)

    这是悦乐书的第303次更新,第322篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第171题(顺位题号是720).给出表示英语词典的字符串单词数组,找到单词中长度最长的单 ...