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. Welcome-to-Swift-23访问控制(Access Control)

    访问控制可以限定你在源文件或模块中访问代码的级别,也就是说可以控制哪些代码你可以访问,哪些代码你不能访问.这个特性可以让我们隐藏功能实现的一些细节,并且可以明确的指定我们提供给其他人的接口中哪些部分是 ...

  2. BZOJ 4552 [Tjoi2016&Heoi2016]排序 ——线段树 二分答案

    听说是BC原题. 好题,二分答案变成01序列,就可以方便的用线段树维护了. 然后就是区间查询和覆盖了. #include <map> #include <cmath> #inc ...

  3. aoj 2226 Merry Christmas

    Merry Christmas Time Limit : 8 sec, Memory Limit : 65536 KB Problem J: Merry Christmas International ...

  4. 转 Python爬虫实战二之爬取百度贴吧帖子

    静觅 » Python爬虫实战二之爬取百度贴吧帖子 大家好,上次我们实验了爬取了糗事百科的段子,那么这次我们来尝试一下爬取百度贴吧的帖子.与上一篇不同的是,这次我们需要用到文件的相关操作. 本篇目标 ...

  5. Vbat 1.8V,接充電器,GPIO_CHG_EN pin 竟然是 high!

    Schematic : Precondition : Vbat 1.8V Plugin adapter Preloader doesn't enable GPIO_CHG_EN Origin : 做個 ...

  6. Android4.2.2 动态显示隐藏屏幕底部的导航栏(对系统源码进行修改)

    需求如题. 在Android4.2.2中,导航栏(也就是屏幕底部的三个按钮,home,back,recentapp)是系统应用SystemUi.apk的一部分,简言之,我们的需求就是让我们的app来控 ...

  7. fuelgauge

    void fg_init(void *queue, void (*bs_fuel_gauge_status)(void)) { fg_init_ready = bs_fuel_gauge_status ...

  8. url相关

    #测试网址: http://localhost/blog/testurl.php?id=5 //获取域名或主机地址 echo$_SERVER['HTTP_HOST']."<br> ...

  9. configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.

    configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+. 一.错误发生情景: 在安装gcc时,执行.c ...

  10. PhpStorm配置svn:Can't use Subversion command line client:svn

    Can't use Subversion command line client:svn 感谢: 萌芽的绿豆的文章:https://www.cnblogs.com/yuanchaoyong/p/616 ...