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字符串.可以在这个字符串中选择一个起点和一个终点使得这个连续区间内所 ...
随机推荐
- Python IO编程-组织文件
对于日常中遇到的批量任务,有些可以通过请求python完成自动化,我非常渴望拥有这些能力,在去年学习了python读写文件之后,我马上迫不及待的开始学习‘组织文件’,经过学习,我发现python组织文 ...
- 紫书 例题 10-27 UVa 10214(欧拉函数)
只看一个象限简化问题,最后答案乘4+4 象限里面枚举x, 在当前这条固定的平行于y轴的直线中 分成长度为x的一段段.符合题目要求的点gcd(x,y) = 1 那么第一段1<= y <= x ...
- Spring学习总结(13)——Spring+Log4j+ActiveMQ实现远程记录日志
应用场景 随着项目的逐渐扩大,日志的增加也变得更快.Log4j是常用的日志记录工具,在有些时候,我们可能需要将Log4j的日志发送到专门用于记录日志的远程服务器,特别是对于稍微大一点的应用.这么做的优 ...
- Java基础学习总结(22)——异常处理
一.异常的概念 异常指的是运行期出现的错误,也就是当程序开始执行以后执行期出现的错误.出现错误时观察错误的名字和行号最为重要. package cn.javastudy.summary; public ...
- Spring官方文档翻译——15.4 处理器映射(Handler mappings)
15.4 处理器映射(Handler mappings) 注:以下将handler翻译成处理器 在Spring早先的版本号中,用户还须要在web应用上下文中定义处理器映射来配置请求(requests) ...
- Error 0x80070020 when you try to start a Web site in IIS 7.0
https://support.microsoft.com/en-hk/help/973094/error-0x80070020-when-you-try-to-start-a-web-site-in ...
- Delegates, Events, and Anonymous Methods 委托、事件与匿名方法
http://www.cnblogs.com/r01cn/archive/2012/11/30/2795977.html
- 洛谷P1919 【模板】A*B Problem升级版(FFT快速傅里叶)
题目描述 给出两个n位10进制整数x和y,你需要计算x*y. 输入输出格式 输入格式: 第一行一个正整数n. 第二行描述一个位数为n的正整数x. 第三行描述一个位数为n的正整数y. 输出格式: 输出一 ...
- mysql安装遇到的坑
安装mysql的三步: mysqld --initialize-insecure mysqld -install net start mysql 中间遇到了坑, 看这篇文章完美的解决了,记录一下 .以 ...
- 一个Web报表项目的性能分析和优化实践(五):重构有助于性能优化么?
项目从初次开发到现在,已经快3年了.期间,有N个工程师参与过. 需求方面:增加减少,反反复复,无数次:人力方面:增加减少,不稳定:时间方面:功能开发着急上线,Bug开发紧急修复. 因此,代码臃肿,问题 ...