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字符串.可以在这个字符串中选择一个起点和一个终点使得这个连续区间内所 ...
随机推荐
- CMDB学习之六 --客户端请求测试,服务端api优化
客户端使用agent 请求测试,agent使用的POST 请求,使用requests模块 本地采集,汇报服务端 #!/usr/bin/env python # -*- coding:utf-8 -*- ...
- Unity 获得视频的某一帧,生成缩略图
Unity 并无直接获取视频某一帧图像的API,所以想要生成缩略图就要自己写方法了, 图片和视频都可以用这种方式生成缩略图,另,转载请标明出处,谢谢. using System.Collections ...
- jquery快速清除复选框、单选框的选中
$(":checked").attr("checked", "");
- Lesson 1 Basic Concepts: Part 3
A cheaper option Some people may not want to buy a domain or pay for hosting because they only have ...
- HDU 5379 Mahjong tree dfs+组合数学
题意:给你一棵树来分配号码,要求是兄弟节点连续并且每一棵子树连续. 思路:因为要求兄弟和子树都是连续的,所以自己打下草稿就可以发现如果一个节点有3个或3个以上的非叶子结点,那么就无论如何也不能达到目的 ...
- 分享一个正则 选择html中所有的单标签
var str = /\B<.+?>/g;
- 常用sql语句及案例
目录 1)基本 2)数学函数 3)rownum 4)分页 5)时间处理 6)字符函数 7)to_number 8)聚合函数 9)学生选课 10)图书馆借阅 基本 --新建表: create table ...
- ES6学习笔记(七)对象的新增方法
1.Object.is() ES5 比较两个值是否相等,只有两个运算符:相等运算符(==)和严格相等运算符(===).它们都有缺点,前者会自动转换数据类型,后者的NaN不等于自身,以及+0等于-0.J ...
- Supervisor 的安装与配置教程
简介 Supervisor是一个进程控制系统. 它是一个C/S系统(注意: 其提供WEB接口给用户查询和控制), 它允许用户去监控和控制在类UNIX系统的进程. 它的目标与launchd, daemo ...
- ios程序启动过程和UIWidnow介绍
一.iOS程序的完整启动过程(有storyboard) 1.先执行main函数,main内部会调用UIApplicationMain函数 2.UIApplicationMain函数里面做了什么事情: ...