codeforces476D
Dreamoon and Sets
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 msuch 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.
Examples
- 1 1
- 5
1 2 3 5
- 2 2
- 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 .
sol:构造出来的肯定是四个互质的数字*K,对于这四个互质的数字要尽量小,容易构造出这样四个
1 2 3 5
7 8 9 11 (每次加6)
没有比上面更小的了
- /*
- 输出n组集合,每组4个。对于任意一组中的4个元素,一组内任意2个数的gcd==k
- 且n组的所有数字各不相同。要使得n组中最大的数字最小。
- */
- #include <bits/stdc++.h>
- using namespace std;
- typedef int ll;
- inline ll read()
- {
- ll s=;
- bool f=;
- char ch=' ';
- while(!isdigit(ch))
- {
- f|=(ch=='-'); ch=getchar();
- }
- while(isdigit(ch))
- {
- s=(s<<)+(s<<)+(ch^); ch=getchar();
- }
- return (f)?(-s):(s);
- }
- #define R(x) x=read()
- inline void write(ll x)
- {
- if(x<)
- {
- putchar('-'); x=-x;
- }
- if(x<)
- {
- putchar(x+''); return;
- }
- write(x/);
- putchar((x%)+'');
- return;
- }
- #define W(x) write(x),putchar(' ')
- #define Wl(x) write(x),putchar('\n')
- int n,K;
- int main()
- {
- int i;
- R(n); R(K);
- Wl((+(n-)*)*K);
- for(i=;i<=n;i++)
- {
- int oo=((i-)*)*K;
- W(K+oo); W(*K+oo); W(*K+oo); Wl(*K+oo);
- }
- return ;
- }
- /*
- Input
- 1 1
- Output
- 5
- 1 2 3 5
- Input
- 2 2
- Output
- 22
- 2 4 6 22
- 14 18 10 16
- */
codeforces476D的更多相关文章
随机推荐
- 开箱即用(out-of-box)的Redis序列号生成器,不用再写任何代码,你值得拥有
先看整体效果 把简单的东西“傻瓜化”是软件开发追求的目标之一.请看下图: 左边是在 application.yml 里配置了3个生成器,右边可以直接注入到代码中使用,注意,不用写任何代码.这酸爽. ...
- 【Vuex】vuex基本介绍与使用
Vuex是什么? 官方解释: Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式.它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化.Vuex 也集 ...
- 服务器配置java
先去链接下载jdk or jre(服务器上这个就好) 然后解压 tar 下载的文件,放到/usr/local/java/jdk_xxx下面 -v: 可视化显示进度. Enables verbose m ...
- 用VS2017进行移动开发(C#、VB.NET)——Progress控件,Smobiler移动开发
Progress控件 一. 样式一 我们要实现上图中的效果,需要如下的操作: 从工具栏上的“Smobiler Components”拖动一个Progress控件到窗体界面上 修改Pr ...
- Asp.Net Web APi 路由的特点
在ASP.NET Web API中,路由是基于HTTP协议 GET请求路由到以GET开头的控制器方法,POST请求路由到以POST开头的控制器方法中,GET方法和GetProducts,都能与GET请 ...
- JS里charCodeAt()和fromCharCode()方法拓展应用:加密与解密
JS实现客户端的网页加密解密技术,可用作选择性隐蔽展示.当然客户端的加密安全度是不能与服务器相提并论,肯定不能用于密码这类内容的加密,但对于一般级别的内容用作展示已经够了. JS加密与解密的解决方案有 ...
- oracle学习笔记(七) 预编译Statement介绍与使用
预编译Statement优点 执行效率高 由于预编译语句使用占位符 "?",在执行SQL之前语句会被先发送到Oracle服务器进行语法检查和编译等工作,并将SQL语句加入到Orac ...
- javaweb中上传视频,并且播放,用上传视频信息为例
1.上传视频信息的jsp页面uploadVideo.jsp <body background="image/bk_hero.jpg"><div id=" ...
- transform旋转,平移,缩放,扭曲 斜切
transform 改变rotate 旋转translate 位移scale 缩放 skew 斜切变形 记得兼容性:-webkit- -moz- -ms- -o- transf ...
- javascript面向对象习题答案
第二章 1.如果我们在控制台中执行下列语句,结果分别是什么?为什么? var a; typeof a; undefined > var s = '1s'; s++; NaN > !!&qu ...