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. Linux下安装Mysql出现的常见问题以及解决办法

     1.安装时候出现 warning: mysql-community-server-5.7.13-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ...

  2. iOS学习笔记24-不断进化的屏幕适配

    一.屏幕适配 iOS的屏幕适配可以分为3大块,代表着不同时期的屏幕适配主流: AutoResizing:在iOS6之前,完全能够胜任,因为当时苹果只有3.5寸屏,加上比较少的支持横屏,它有非常大的局限 ...

  3. 【bzoj2339】[HNOI2011]卡农 dp+容斥原理

    题目描述 题解 dp+容斥原理 先考虑有序数列的个数,然后除以$m!$即为集合的个数. 设$f[i]$表示选出$i$个集合作为满足条件的有序数列的方案数. 直接求$f[i]$较为困难,考虑容斥,满足条 ...

  4. BZOJ2938 [Poi2000]病毒 【AC自动机】

    题目 二进制病毒审查委员会最近发现了如下的规律:某些确定的二进制串是病毒的代码.如果某段代码中不存在任何一段病毒代码,那么我们就称这段代码是安全的.现在委员会已经找出了所有的病毒代码段,试问,是否存在 ...

  5. [APIO2009]抢掠计划 ($Tarjan$,最长路)

    题目链接 Solution 裸题诶... 直接 \(Tarjan\) 缩点+ \(SPFA\) 最长路即可. 不过在洛谷上莫名被卡... RE两个点... Code #include<bits/ ...

  6. css3实现连续不断的波浪

    给的波浪要比容器大,然后在左边准备一个相同的,注意,波浪头尾要能衔接起来,接着运动的长度为波浪的宽度,然后不断重复就好了

  7. Road(bzoj 2750)

    Description C国有n座城市,城市之间通过m条单向道路连接.一条路径被称为最短路,当且仅当不存在从它的起点到终点的另外一条路径总长度比它小.两条最短路不同,当且仅当它们包含的道路序列不同.我 ...

  8. 一款多功能的移动端滚动选择器,支持单选到多选、支持多级级联、提供自定义回调函数、提供update函数二次渲染、重定位函数、兼容pc端拖拽等等..

    https://github.com/onlyhom/mobileSelect.js/blob/master/docs/README-CN.md mobileSelect.js 一款多功能的移动端滚动 ...

  9. es6总结(十)--class

  10. git超详细教程【转】

    转自:http://blog.csdn.net/liuwengai/article/details/52072344 GitHub操作总结 : 总结看不明白就看下面的详细讲解.   GitHub操作流 ...