D. Dreamoon and Sets(Codeforces Round #272)
1 second
256 megabytes
standard input
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 si, sj fromS,
.
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.
The single line of the input contains two space separated integers n, k (1 ≤ n ≤ 10 000, 1 ≤ k ≤ 100).
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.
1 1
5
1 2 3 5
2 2
22
2 4 6 22
14 18 10 16
For the first example it's easy to see that set {1, 2, 3, 4} isn't a valid set of rank 1 since
.
构造。当k等于1时,推几组数据。比如1,2,3,5;7,8,9,11;13,14,15,17。19,20,21,23;25,26,27,29。就会发现是以6为周期,而对每一个周期内的数乘以k就会使周期内的数两两的最大公约数为k。
代码:
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int n, k;
scanf("%d %d", &n, &k);
int a = 1, b = 2, c = 3, d = 5;
printf("%d\n", (d * k + 6 * k * (n- 1)));
a*=k;
b*=k;
c*=k;
d*=k;
for(int i = 0; i < n; i++)
{
printf("%d %d %d %d\n",a, b, c, d);
a += 6 * k;
b += 6 * k;
c += 6 * k;
d += 6 * k;
}
}
D. Dreamoon and Sets(Codeforces Round #272)的更多相关文章
- B. Dreamoon and WiFi(Codeforces Round 272)
B. Dreamoon and WiFi time limit per test 1 second memory limit per test 256 megabytes input standard ...
- A. Dreamoon and Stairs(Codeforces Round #272)
A. Dreamoon and Stairs time limit per test 1 second memory limit per test 256 megabytes input standa ...
- E. Dreamoon and Strings(Codeforces Round #272)
E. Dreamoon and Strings time limit per test 1 second memory limit per test 256 megabytes input stand ...
- Codeforces Round #272 (Div. 2) 题解
Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs time limit per test 1 second memory limit per ...
- Codeforces Round #272 (Div. 2) D. Dreamoon and Sets 构造
D. Dreamoon and Sets 题目连接: http://www.codeforces.com/contest/476/problem/D Description Dreamoon like ...
- Codeforces Round #272 (Div. 2) D.Dreamoon and Sets 找规律
D. Dreamoon and Sets Dreamoon likes to play with sets, integers and . is defined as the largest p ...
- Codeforces Round #272 (Div. 2)AK报告
A. Dreamoon and Stairs time limit per test 1 second memory limit per test 256 megabytes input standa ...
- 「日常训练」Watering Flowers(Codeforces Round #340 Div.2 C)
题意与分析 (CodeForces 617C) 题意是这样的:一个花圃中有若干花和两个喷泉,你可以调节水的压力使得两个喷泉各自分别以\(r_1\)和\(r_2\)为最远距离向外喷水.你需要调整\(r_ ...
- 「日常训练」Alternative Thinking(Codeforces Round #334 Div.2 C)
题意与分析 (CodeForces - 603A) 这题真的做的我头疼的不得了,各种构造样例去分析性质... 题意是这样的:给出01字符串.可以在这个字符串中选择一个起点和一个终点使得这个连续区间内所 ...
随机推荐
- QQ音乐
import re import requestsimport json class Search: def __init__(self, song): ''' self.vkey_url ---&g ...
- 题解 P3521 【[POI2011]ROT-Tree Rotations】
这道题采用权值线段树合并的解法. 首先讲一下解法中出现的两个概念:权值线段树与线段树合并. 所谓权值线段树,可以理解为维护的信息反过来的普通线段树,我个人认为值域线段树这个名字其实要准确一些. 举个例 ...
- Spring官方文档翻译——15.4 处理器映射(Handler mappings)
15.4 处理器映射(Handler mappings) 注:以下将handler翻译成处理器 在Spring早先的版本号中,用户还须要在web应用上下文中定义处理器映射来配置请求(requests) ...
- 异常Exception
try…catch…finally恐怕是大家再熟悉不过的语句了,而且感觉用起来也是很简单,逻辑上似乎也是很容易理解.不过,我亲自体验的“教训”告诉我,这个东西可不是想象中的那么简单.听话.不信?那你看 ...
- Flex之柱状图实例
Flex之柱状图实例 <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns ...
- 【Django】安装及配置
目录 MVC框架与MTV框架 Django的MTV模式 Django框架图示 安装及配置 创建一个Django项目 目录介绍 运行Django项目 启动Django报错 模版文件配置 静态文件配置 A ...
- blkid---对系统块设备信息查询
在Linux下可以使用blkid命令对查询设备上所采用文件系统类型进行查询.blkid主要用来对系统的块设备(包括交换分区)所使用的文件系统类型.LABEL.UUID等信息进行查询.要使用这个命令必须 ...
- C# async/await异步编程深入理解
异步函数简介 一般指 async 修饰符声明得.可包含await表达式得方法或匿名函数. 声明方式 异步方法的声明语法与其他方法完全一样, 只是需要包含 async 关键字.async可以出现在返回值 ...
- 【Mysql】经常使用指令之——忘记password
上一篇文章基本总结了下myql下通过指令怎么创建用户.详见:[Mysql]经常使用指令之--用户操作(创建,授权,改动.删除) 今天说下特殊情况,忘记password了怎么办??? 重装.删除配置等能 ...
- UVA - 10032 Tug of War (二进制标记+01背包)
Description Problem F: Tug of War A tug of war is to be arranged at the local office picnic. For the ...