codeforces 477B B. Dreamoon and Sets(构造)
题目链接:
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, sjfrom S, .
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 题意: 构造n个集合,每个集合里面4个数,每两个数的gcd=k,问这些数里面的最大的那个数最小是多少,和这些集合是怎样的; 思路: 1,2,3,5 7,8,9,11, 13,14,15,17 就是这样的规律,跟原来那个什么6*n+1,6*n+5折两个数有可能是质数一样,每6个相邻的数里面两两互质的就是6*n+1,6*n+2,6*n+3,6*n+5了;
然后乘上k就好了; AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack>
#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const int mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e6+20;
const int maxn=1e5+110;
const double eps=1e-12; int main()
{
int n,k;
read(n);read(k);
cout<<(n-1)*6*k+5*k<<endl;
For(i,1,n)
{
int t=(i-1)*6+1;
printf("%d %d %d %d\n",t*k,t*k+k,t*k+2*k,t*k+4*k);
} return 0;
}
codeforces 477B B. Dreamoon and Sets(构造)的更多相关文章
- 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】 B. Dreamoon and Sets
B. Dreamoon and Sets time limit per test 1 second memory limit per test 256 megabytes input standard ...
- D. Dreamoon and Sets(Codeforces Round #272)
D. Dreamoon and Sets time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 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 ...
- cf(#div1 B. Dreamoon and Sets)(数论)
B. Dreamoon and Sets time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #272 (Div. 2) D. Dreamoon and Sets (思维 数学 规律)
题目链接 题意: 1-m中,四个数凑成一组,满足任意2个数的gcd=k,求一个最小的m使得凑成n组解.并输出 分析: 直接粘一下两个很有意思的分析.. 分析1: 那我们就弄成每组数字都互质,然后全体乘 ...
- Codeforces Gym 100187K K. Perpetuum Mobile 构造
K. Perpetuum Mobile Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/pro ...
- Codeforces 1090D - Similar Arrays - [思维题][构造题][2018-2019 Russia Open High School Programming Contest Problem D]
题目链接:https://codeforces.com/contest/1090/problem/D Vasya had an array of n integers, each element of ...
- Codeforces 610C:Harmony Analysis(构造)
[题目链接] http://codeforces.com/problemset/problem/610/C [题目大意] 构造出2^n个由1和-1组成的串使得其两两点积为0 [题解] 我们可以构造这样 ...
随机推荐
- 泛函编程(19)-泛函库设计-Parallelism In Action
上节我们讨论了并行运算组件库的基础设计,实现了并行运算最基本的功能:创建新的线程并提交一个任务异步执行.并行运算类型的基本表达形式如下: import java.util.concurrent._ o ...
- 容器---List和AbstractList
一.前言 前面我们介绍了Collection及其抽象实现,在JAVA的容器体系里,由Collection派生出来的有两大体系,即List和Map.本文以及后续文章将重点分析List体系.本文将重点分析 ...
- js 自带的 reduce() 方法
1.方法说明 , Array的reduce()把一个函数作用在这个Array的[x1, x2, x3...]上,这个函数必须接收两个参数,reduce()把结果继续和序列的下一个元素做累积计算,其效果 ...
- 怎样高效地去判断Array中是否包含某个值?
问题 怎样去判断Array(无序)中是否包含某个值呢? 这是一个在Java中经常被问到的问题.它也是Stack Overflow上投票前几的一个问题.下面将展示投票前几的几个回答,这些回答使用不同的方 ...
- [Architecture Design] 累进式Domain Layer
[Architecture Design] 累进式Domain Layer 前言 本篇的内容大幅度的简化了分析设计.面向对象等等相关知识,用以传达累进式Domain Layer的核心概念.实际开发软件 ...
- java响应微信用户信息(wechat4j)
你的微信应用程序接收到用户发送的消息事件之后,可以进行响应.wechat4j支持多种消息的响应. wechat4j响应消息的部分在wechat4j的入口WechatSupport.java中定义,直接 ...
- js填写银行卡号,每隔4位数字加一个空格
1.原生js写法 !function () { document.getElementById('bankCard').onkeyup = function (event) { var v = thi ...
- C#进制转换
//十进制转二进制 Console.WriteLine(Convert.ToString(69, 2)); //十进制转八进制 Console.WriteLine(Convert.ToString(6 ...
- SAP技术相关Tcode
ABAP的常用tcode 开发----------------------------------------------- SE51 屏幕制作 SE91 MESSAGE OBJECT SE80 ...
- SharePoint 2010 External List Paging – Server Side
http://lightningtools.com/bcs/sharepoint-2010-external-list-paging-server-side/ When you are using a ...