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

题解:这一题事实上就是找规律。能够发现题目事实上就是要找n堆数,每堆4个并且要互质,能够发现假设依照1 2 3 5,7 8 9 11,13 14 15 17……这样一直构造下去,最后就能够得到解。

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

【CODEFORCES】 B. Dreamoon and Sets的更多相关文章

  1. 【CODEFORCES】 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】 C. Dreamoon and Strings

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

  3. 【Codeforces】CF367D Sereja and Sets (数学)

    题目大意 1到n这n个正整数被分成了m个不相交的集合(集合不一定连续),现在从这m个集合中选出最少个数的集合,满足对于[1,n]中任意一个长度为d的区间都至少有一个数字出现在已选集合中.(1 < ...

  4. 【Codeforces】Round #491 (Div. 2) 总结

    [Codeforces]Round #491 (Div. 2) 总结 这次尴尬了,D题fst,E没有做出来.... 不过还好,rating只掉了30,总体来说比较不稳,下次加油 A:If at fir ...

  5. 【Codeforces】Round #488 (Div. 2) 总结

    [Codeforces]Round #488 (Div. 2) 总结 比较僵硬的一场,还是手速不够,但是作为正式成为竞赛生的第一场比赛还是比较圆满的,起码没有FST,A掉ABCD,总排82,怒涨rat ...

  6. 【CodeForces】601 D. Acyclic Organic Compounds

    [题目]D. Acyclic Organic Compounds [题意]给定一棵带点权树,每个点有一个字符,定义一个结点的字符串数为往下延伸能得到的不重复字符串数,求min(点权+字符串数),n&l ...

  7. 【Codeforces】849D. Rooter's Song

    [算法]模拟 [题意]http://codeforces.com/contest/849/problem/D 给定n个点从x轴或y轴的位置p时间t出发,相遇后按对方路径走,问每个数字撞到墙的位置.(还 ...

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

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

  9. 【CodeForces】983 E. NN country 树上倍增+二维数点

    [题目]E. NN country [题意]给定n个点的树和m条链,q次询问一条链(a,b)最少被多少条给定的链覆盖.\(n,m,q \leq 2*10^5\). [算法]树上倍增+二维数点(树状数组 ...

随机推荐

  1. SpriteKit-(SKNode)

    1.初始化 + (instancetype)node; + (nullable instancetype)nodeWithFileNamed:(NSString*)filename; 2.返回边界边框 ...

  2. java面试题之谈谈你对java的理解

    平台无关性:一处编译到处运行 GC:不用像c++那样手动释放堆内容 语言特性:泛型.反射.lamda表达式 面向对象:封装.继承.多态 类库:集合.并发库.网络库.IO库 异常处理

  3. 关于vue属性绑定的问题

    <el-submenu index="></el-submenu> 类似于这样的形式,这里的index是以string的数据格式存在的. <el-submenu ...

  4. 树上的路径 BZOJ 3784

    树上的路径 [问题描述] 给定一个N个结点的树,结点用正整数1..N编号.每条边有一个正整数权值.用d(a,b)表示从结点a到结点b路边上经过边的权值.其中要求a<b.将这n*(n-1)/2个距 ...

  5. scss 侧边栏_图片

    html <!doctype html><html lang="zh-CN"><head> <meta charset="UTF ...

  6. Linux 之 CentOS练习

    CentOS练习 参考教程:[千峰教育] 一.安装配置CentOS 1.安装虚拟机:VirtualBox. (1)软件下载:https://www.virtualbox.org/. (2)一路点击下一 ...

  7. django相关字段解释(slug)

    1.slug:用于生成一个有意义(valid, meaninful)URL 参考(http://stackoverflow.com/questions/427102/what-is-a-slug-in ...

  8. window下golang使用gRPC入门案例&net core客户端

    gRPC是google开源高性能分布式RPC框架,支持http/2 双向数据流传输及Protobuff,可以在任何环境下运行. 它可以有效地将数据中心内和跨数据中心的服务与可插拔支持进行负载均衡,跟踪 ...

  9. 小程序 之使用HMACSHA1算法加密报文

    首先说说我们前端常用的加密技术, 我们常用的加密技术有:如MD5加密,base64加密 今天要说的是HMACSHA1加密技术 先介绍下什么是SHA1算法, 安全哈希算法(Secure Hash Alg ...

  10. (1)sqlite基础

    一.安装sqlite 下载页面:http://www.sqlite.org/download.html 1.下载 sqlite-tools-win32-*.zip 和 sqlite-dll-win32 ...