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的更多相关文章
随机推荐
- SmartSql Zookeeper分布式配置
安装 SmartSql.ZooKeeperConfig Install-Package SmartSql.ZooKeeperConfig Demo string connStr = "192 ...
- Python编程从入门到实践笔记——文件
Python编程从入门到实践笔记——文件 #coding=gbk #Python编程从入门到实践笔记——文件 #10.1从文件中读取数据 #1.读取整个文件 file_name = 'pi_digit ...
- 内核中 EXPORT_SYMBOL 标志分析
内核版本:Linux-4.19 1. EXPORT_SYMBOL 的作用: EXPORT_SYMBOL 定义的函数或者符号对全部内核代码公开,不用修改内核代码就可以在其它内核模块中直接调用,即使用 E ...
- 使用SSL安全证书和nginx配置将域名HTTPS化
一.在阿里云后台申请免费版证书: 二.在域名解析里面添加记录: 三.提交审核: 四.等待审核通过后,下载nginx证书: 五.按照文档修改nginx配置文件: https://help.aliyun. ...
- 初步认识Swiper_前端交互控制神器_滚动3D切换等特效简单制作
前言: 本人在项目的工作中负责研发,页面及交互基本都是交给前端去做的.以前前端写的东西大概都知道,都是一些JS,CSS和HTML等的一些基本控制,都懂!但是今天前端突然做了一个具有特殊效果的DOM:页 ...
- jQuery(五)、筛选
1 过滤 1.eq(index | -index) 获取第N个元素,index为元素索引,-index值基于最后一个元素的位置(从 1 开始) 2.first() 获取第一个元素 3.last() 获 ...
- Android为TV端助力 外挂字幕(设置颜色,大小,位置,微调字幕)
前提摘要: 可以给电影加字幕,目前支持srt和ass格式, 功能摘要: 支持微调字幕,设置大小,颜色,位置 1 .字幕解析类 package com.hhzt.iptv.lvb_x.utils; ...
- python3+arcface2.0 离线人脸识别 demo
python3+虹软2.0的所有功能整合测试完成,并对虹软所有功能进行了封装,现提供demo主要功能,1.人脸识别2.人脸特征提取3.特征比对4.特征数据存储与比对其他特征没有添加 sdk 下载请戳这 ...
- (办公)springmvc->controller的统一异常层,返回json
controller里面写的代码,很多时候,没有写try{}catch(Exceiption ex){},结果就是系统出错,就算是接口,参数正确也会返回404,这个是不应该的. 下面是代码,以后参考 ...
- Numpy库的学习(一)
今天来学习一下Python库中,支持高级大量的维度数组与矩阵运算的神奇的Numpy库 Numpy同时也对数组运算提供大量的数学函数,对于大量计算运行效率极好 是大量机器学习框架的基础库 废话不多说,直 ...