【CODEFORCES】 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
For the first example it's easy to see that set {1, 2, 3, 4} isn't a valid set of rank 1 since .
题解:这一题事实上就是找规律。能够发现题目事实上就是要找n堆数,每堆4个并且要互质,能够发现假设依照1 2 3 5,7 8 9 11,13 14 15 17……这样一直构造下去,最后就能够得到解。
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int d[10005][4],n,k; int main()
{
scanf("%d%d",&n,&k);
for (int i=1;i<=n;i++)
{
d[i][0]=6*i-5;
d[i][1]=6*i-4;
d[i][2]=6*i-3;
d[i][3]=6*i-1;
}
printf("%d\n",d[n][3]*k);
for (int i=1;i<=n;i++)
{
for (int j=0;j<4;j++) printf("%d ",d[i][j]*k);
printf("\n");
}
return 0;
}
【CODEFORCES】 B. Dreamoon and Sets的更多相关文章
- 【CODEFORCES】 A. Dreamoon and Sums
A. Dreamoon and Sums time limit per test 1.5 seconds memory limit per test 256 megabytes input stand ...
- 【CODEFORCES】 C. Dreamoon and Strings
C. Dreamoon and Strings time limit per test 1 second memory limit per test 256 megabytes input stand ...
- 【Codeforces】CF367D Sereja and Sets (数学)
题目大意 1到n这n个正整数被分成了m个不相交的集合(集合不一定连续),现在从这m个集合中选出最少个数的集合,满足对于[1,n]中任意一个长度为d的区间都至少有一个数字出现在已选集合中.(1 < ...
- 【Codeforces】Round #491 (Div. 2) 总结
[Codeforces]Round #491 (Div. 2) 总结 这次尴尬了,D题fst,E没有做出来.... 不过还好,rating只掉了30,总体来说比较不稳,下次加油 A:If at fir ...
- 【Codeforces】Round #488 (Div. 2) 总结
[Codeforces]Round #488 (Div. 2) 总结 比较僵硬的一场,还是手速不够,但是作为正式成为竞赛生的第一场比赛还是比较圆满的,起码没有FST,A掉ABCD,总排82,怒涨rat ...
- 【CodeForces】601 D. Acyclic Organic Compounds
[题目]D. Acyclic Organic Compounds [题意]给定一棵带点权树,每个点有一个字符,定义一个结点的字符串数为往下延伸能得到的不重复字符串数,求min(点权+字符串数),n&l ...
- 【Codeforces】849D. Rooter's Song
[算法]模拟 [题意]http://codeforces.com/contest/849/problem/D 给定n个点从x轴或y轴的位置p时间t出发,相遇后按对方路径走,问每个数字撞到墙的位置.(还 ...
- codeforces 477B B. Dreamoon and Sets(构造)
题目链接: B. Dreamoon and Sets time limit per test 1 second memory limit per test 256 megabytes input st ...
- 【CodeForces】983 E. NN country 树上倍增+二维数点
[题目]E. NN country [题意]给定n个点的树和m条链,q次询问一条链(a,b)最少被多少条给定的链覆盖.\(n,m,q \leq 2*10^5\). [算法]树上倍增+二维数点(树状数组 ...
随机推荐
- ABP数据库的迁移
添加表,一(Test)对多(Test1)关系 Test using Abp.Domain.Entities.Auditing; using System; using System.Collectio ...
- HDU——2093考试排名(string类及其函数的运用以及istringstream)
考试排名 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- BZOJ3930 [CQOI2015]选数 【容斥】
题目 我们知道,从区间[L,H](L和H为整数)中选取N个整数,总共有(H-L+1)^N种方案.小z很好奇这样选出的数的最大公约数的规律,他决定对每种方案选出的N个整数都求一次最大公约数,以便进一步研 ...
- BZOJ4566 [Haoi2016]找相同字符 【后缀数组】
题目 给定两个字符串,求出在两个字符串中各取出一个子串使得这两个子串相同的方案数.两个方案不同当且仅当这两 个子串中有一个位置不同. 输入格式 两行,两个字符串s1,s2,长度分别为n1,n2.1 & ...
- 学习 JSP:第一步Eclipse+Tomcat+jre(配置环境)
[下载软件](例子version:版本号) Eclipse从官网下载(version:4.7)http://www.eclipse.org/downloads/ jre从官网下载(version:1. ...
- 如何在github上寻找漏洞
https://github.com/search?p=2&q=eval%28%24_POST[&ref=searchresults&type=Code 1.$_GET s ...
- [暑假集训--数位dp]LightOJ1140 How Many Zeroes?
Jimmy writes down the decimal representations of all natural numbers between and including m and n, ...
- Gcd(bzoj 2818)
Description 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. Input 一个整数N Output 如题 Sample Input 4 Sam ...
- NEERC15
2015-2016 ACM-ICPC Northeastern European Regional Contest 再开一个新坑吧 目前姿势有限,C.H.I仍然处于弃坑状态 代码戳这里 Problem ...
- Go -- 接口赋值
在go语言中,接口赋值分为2中情况: 1.将对象实例赋值给接口: 2.将一个接口赋值给另一个接口. 1.将对象实例赋值给接口: 要求对象实现了接口的所有方法. 2.将接口赋值给另一个接口: 假设接口A ...