B. 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 si, sj from S, .

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 n, k (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 .

题意: 给你任意n,k,要你求出n组gcd(si,sj)=k的四个元素的组合.........

其实对于gcd(a,b)=k,我们只需要求出gcd(a,b)=1;然后进行gcd(a,b)*k=k;

不难发现这些数是固定不变的而且还有规律可循,即1,2,3,5    7 8 9 11   13 14 15 17   每一个段直接隔着2,段内前3个连续,后一个隔着2.....

代码:

 #include<cstdio>
#include<cstring>
using namespace std;
const int maxn=;
__int64 ans[maxn][];
void work()
{
__int64 k=;
for(int i=;i<;i++)
{
ans[i][]=k++;
ans[i][]=k++;
ans[i][]=k++;
ans[i][]=++k;
k+=;
}
}
int main()
{
int n,k;
work();
while(scanf("%d%d",&n,&k)!=EOF)
{
printf("%I64d\n",ans[n-][]*k);
for(int i=;i<n;i++)
printf("%I64d %I64d %I64d %I64d\n",ans[i][]*k,ans[i][]*k,ans[i][]*k,ans[i][]*k);
}
return ;
}

cf(#div1 B. Dreamoon and Sets)(数论)的更多相关文章

  1. cf(#div1 A. Dreamoon and Sums)(数论)

    A. Dreamoon and Sums time limit per test 1.5 seconds memory limit per test 256 megabytes input stand ...

  2. codeforces 477B B. Dreamoon and Sets(构造)

    题目链接: B. Dreamoon and Sets time limit per test 1 second memory limit per test 256 megabytes input st ...

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

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

  4. CF 984C Finite or not? (数论)

    CF 984C Finite or not? (数论) 给定T(T<=1e5)组数据,每组数据给出十进制表示下的整数p,q,b,求问p/q在b进制意义下是否是有限小数. 首先我们先把p/q约分一 ...

  5. 【CODEFORCES】 B. Dreamoon and Sets

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

  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. D. Dreamoon and Sets(Codeforces Round #272)

    D. Dreamoon and Sets time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. cf 450b 矩阵快速幂(数论取模 一大坑点啊)

    Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, ple ...

  9. cf 645F Cowslip Collections 组合数学 + 简单数论

    http://codeforces.com/contest/645/problem/F F. Cowslip Collections time limit per test 8 seconds mem ...

随机推荐

  1. VBA中的FileSystemObject对象(FSO)和文本流

    对FileSystemObject一直略有耳闻,VBA爱好者常常简称为FSO对象. 在Scripting类库中有三个可以直接使用NEW关键字实例化的类,第一个就是常用的字典,第三个是FSO. 一.FS ...

  2. [SAP ABAP开发技术总结]EXIT-COMMAND

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  3. mysql密码忘记或者不知道,怎么办?

    运行cmd: 输入mysql回车,如果成功,将出现MySQL提示符 > 连接权限数据库>use mysql; (>是本来就有的提示符,别忘了最后的分号) 修改改密码:> upd ...

  4. install Matlab2016b on Ubuntu 14.04

    From Download Download the install file from Download MATLAB, Simulink, Stateflow, and Other MathWor ...

  5. Domion OA 日记

    我现在使用的是IBM的 Lotus Dimion 8.5 以下内容是个人的浅显了解,在此记录下,已作为后续记录的翻看 第一次接触文档型数据库,确实颠覆了我对数据模型的认知,我之前一直用sql的 文档型 ...

  6. Scrum Meeting---Three(2015-10-27)

    今日已完成任务和明日要做的任务 姓名 今日已完成任务 今日时间 明日计划完成任务 估计用时 董元财 今日我学习了Java Web,同时安装好了我的MySQL 4h 进行数据库设计以及Web项目的创建 ...

  7. iOS - UITextView

    前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UITextView : UIScrollView <UITextInput> @available(i ...

  8. [转载] 一致性问题和Raft一致性算法

    原文: http://daizuozhuo.github.io/consensus-algorithm/ raft 协议确实比 paxos 协议好懂太多了. 一致性问题 一致性算法是用来解决一致性问题 ...

  9. bootstrap学习笔记<十一>(导航条)

    基础导航条.样式:class="navbar navbar-default",属性:role="navigation" <div class=" ...

  10. MTK Camera 开机启动流程(转载)

    一.MTK平台Camera框架 MTK平台的Camera的架构见下图, 这里主要介绍kernel部分和HAL层部分. 1.Kernel 部分主要有两块: 1.1.image sensordriver, ...