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;
}
}
最新文章
- 浅谈SQL Server中的三种物理连接操作
- C# 指定Webbrowser控件所用IE内核版本
- Hadoop日记Day18---MapReduce排序分组
- 浏览器何时发送一个Option请求
- Javascript 笔记与总结(2-9)获取运行时的 style 对象
- PAT乙级 1001. 害死人不偿命的(3n+1)猜想 (15)
- C++-不要在构造和析构函数中调用虚函数
- PB学习笔记(一)
- classic asp中使用ADODB.Command防止sql injection
- Gulp前端构建工具
- 我对CSS中的BFC的理解
- linux重要的守护进程
- 面向对象_06【抽象类:abstract、接口:interface、实现:implements】
- 关于CheckStyle在eclipse出现的问题
- 移动端js调试工具:eruda
- Python3 Tcp未发送/接收完数据即被RST处理办法
- JavaScript知识点总结[部分]
- for循环的字节码
- webSocket协议与Socket的区别
- USB gadget学习笔记
热门文章
- ln---创建链接
- Win10+TensorFlow-gpu pip方式安装,anaconda方式安装
- 八 rowkey设计 几种方法
- 为OLED屏添加GUI支持3:字库
- CountDownLatch &;amp; CyclicBarrier源代码实现解析
- Android开发之Volley网络通信框架
- SQLite: sqlite_master(转)
- SCOPE_IDENTITY()和 SELECT @@IDENTITY 的用法
- [Chromium文档转载,第003章]Proposal: Mojo Synchronous Methods
- R学习:《R语言数据分析与挖掘实战》PDF代码