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;
}
}



D. Dreamoon and Sets(Codeforces Round #272)的更多相关文章

  1. B. Dreamoon and WiFi(Codeforces Round 272)

    B. Dreamoon and WiFi time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. A. Dreamoon and Stairs(Codeforces Round #272)

    A. Dreamoon and Stairs time limit per test 1 second memory limit per test 256 megabytes input standa ...

  3. E. Dreamoon and Strings(Codeforces Round #272)

    E. Dreamoon and Strings time limit per test 1 second memory limit per test 256 megabytes input stand ...

  4. Codeforces Round #272 (Div. 2) 题解

    Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs time limit per test 1 second memory limit per ...

  5. Codeforces Round #272 (Div. 2) D. Dreamoon and Sets 构造

    D. Dreamoon and Sets 题目连接: http://www.codeforces.com/contest/476/problem/D Description Dreamoon like ...

  6. Codeforces Round #272 (Div. 2) D.Dreamoon and Sets 找规律

    D. Dreamoon and Sets   Dreamoon likes to play with sets, integers and .  is defined as the largest p ...

  7. Codeforces Round #272 (Div. 2)AK报告

    A. Dreamoon and Stairs time limit per test 1 second memory limit per test 256 megabytes input standa ...

  8. 「日常训练」Watering Flowers(Codeforces Round #340 Div.2 C)

    题意与分析 (CodeForces 617C) 题意是这样的:一个花圃中有若干花和两个喷泉,你可以调节水的压力使得两个喷泉各自分别以\(r_1\)和\(r_2\)为最远距离向外喷水.你需要调整\(r_ ...

  9. 「日常训练」Alternative Thinking(Codeforces Round #334 Div.2 C)

    题意与分析 (CodeForces - 603A) 这题真的做的我头疼的不得了,各种构造样例去分析性质... 题意是这样的:给出01字符串.可以在这个字符串中选择一个起点和一个终点使得这个连续区间内所 ...

随机推荐

  1. Vs2012在Linux开发中的应用(1):开发环境

    在Linux的开发过程中使用过多个IDE.code::blocks.eclipse.source insight.还有嵌入式厂商提供的各种IDE.如VisualDsp等,感觉总是不如vs强大好用.尽管 ...

  2. [B cannot be cast to java.lang.String

    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.inv ...

  3. 2.最详细的WSDD配置文件注释

    https://blog.csdn.net/u011063151/article/details/52590282

  4. HDU 1005 Number Sequence(矩阵)

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  5. OpenGL编程逐步深入(一)创建一个窗口

    原文地址:http://ogldev.atspace.co.uk/ 原文中使用gnu make进行项目管理,本系列文章使用visual studio2012.在翻译过程中并非直译,加入了一些笔者个人观 ...

  6. Sub Thread to update main Thread (UI) 2

    Sub Thread to update main Thread (UI)  2 Handler.post(somethread); Handler.sendMessage("Msg&quo ...

  7. jquery<=======>js实现方法

    http://haorooms.com/post/js_shixian_jquery

  8. webpack+react实现echarts可视化配置

    先上效果 开发环境要求 需要事先安装node及npm 前期准备 1.创建文件夹react-echarts-editor2.在项目根目录(以下称根目录)下创建src目录3.在项目根目录下创建dist目录 ...

  9. Httpd 文件服务器的搭建

    服务器信息 系统: CentOS 安装操作 安装 httpd 直接通过 yum 安装: yum install httpd 安装完成之后,可以检查版本: http 查看版本 httpd -versio ...

  10. jq 克隆 移除table

    function addRow2(node){ var obj = $("tr[name='info']:last"); var objClone = $(obj).clone() ...