cf(#div1 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, sj from 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,k,要你求出n组gcd(si,sj)=k的四个元素的组合.........
其实对于gcd(a,b)=k,我们只需要求出gcd(a,b)=1;然后进行gcd(a,b)*k=k;
不难发现这些数是固定不变的而且还有规律可循,即1,2,3,5 7 8 9 11 13 14 15 17 每一个段直接隔着2,段内前3个连续,后一个隔着2.....
代码:
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=;
__int64 ans[maxn][];
void work()
{
__int64 k=;
for(int i=;i<;i++)
{
ans[i][]=k++;
ans[i][]=k++;
ans[i][]=k++;
ans[i][]=++k;
k+=;
}
}
int main()
{
int n,k;
work();
while(scanf("%d%d",&n,&k)!=EOF)
{
printf("%I64d\n",ans[n-][]*k);
for(int i=;i<n;i++)
printf("%I64d %I64d %I64d %I64d\n",ans[i][]*k,ans[i][]*k,ans[i][]*k,ans[i][]*k);
}
return ;
}
cf(#div1 B. Dreamoon and Sets)(数论)的更多相关文章
- cf(#div1 A. Dreamoon and Sums)(数论)
A. Dreamoon and Sums time limit per test 1.5 seconds memory limit per test 256 megabytes input stand ...
- 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 Round #272 (Div. 2) D. Dreamoon and Sets 构造
D. Dreamoon and Sets 题目连接: http://www.codeforces.com/contest/476/problem/D Description Dreamoon like ...
- CF 984C Finite or not? (数论)
CF 984C Finite or not? (数论) 给定T(T<=1e5)组数据,每组数据给出十进制表示下的整数p,q,b,求问p/q在b进制意义下是否是有限小数. 首先我们先把p/q约分一 ...
- 【CODEFORCES】 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 找规律
D. Dreamoon and Sets Dreamoon likes to play with sets, integers and . is defined as the largest p ...
- 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 ...
- cf 450b 矩阵快速幂(数论取模 一大坑点啊)
Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, ple ...
- cf 645F Cowslip Collections 组合数学 + 简单数论
http://codeforces.com/contest/645/problem/F F. Cowslip Collections time limit per test 8 seconds mem ...
随机推荐
- COM/ATL 资料收集
COM/ATL COM基础知识 COM技术分类
- [转]Jenkins CommonCollections 完美利用(演示)工具
博主URL:http://tools.changesec.com/Jenkins-CommonCollections-Exploit/ 提交漏洞总是要证明漏洞危害,老外写的java代码又有bug,所以 ...
- Beaglebone Black– 智能家居控制系统 LAS - 刷 WiFi 模块 ESP8266 Firmware 和 ESP8266 直接收发 GPIO 信号
用 Windows 来刷 ESP8266 固件有很多中文教程,来试试直接用 BBB 刷吧.目标是 NodeMCU,ESP-01 可用,就是我买的那个. 接线方式在上一篇.当 echo ‘BB-UART ...
- 7.mybatis一对多关联查询
和第5节一对一查询类似,但是不同的是,一对一使用的是association,而一对多使用collection. 实例: 1个班级Class,对应1个老师Teacher,对应多个学生Student 1. ...
- Spark.ML之PipeLine学习笔记
地址: http://spark.apache.org/docs/2.0.0/ml-pipeline.html Spark PipeLine 是基于DataFrames的高层的API,可以方便用户 ...
- SQL Povit
),) ,,@logistics_code='All',@fee_type='All' ),) ,@strDateList='',@from_date=cast((ltrim(@yr)+'-'+ltr ...
- 基于Spark ALS构建商品推荐引擎
基于Spark ALS构建商品推荐引擎 一般来讲,推荐引擎试图对用户与某类物品之间的联系建模,其想法是预测人们可能喜好的物品并通过探索物品之间的联系来辅助这个过程,让用户能更快速.更准确的获得所需 ...
- 算法_队列的Java通用数组实现
在实现Queue的API的时候,可以使用两个实例变量做索引,一个变量head指向队列的开头,另一个变量tail指向队列的结尾.在删除一个元素的时候,使用head访问,并将head+1,插入一个元素的时 ...
- Velocity教程 (zhuan)
http://blog.csdn.net/qq_25237663/article/details/52262532 ****************************************** ...
- C# Socket编程(2)识别网络主机
通过前面的笔记我们可以知道:一个客户端要想发起一次通信,先决条件就是需要知道运行在服务端程序的主机的IP地址是多少,端口号是多少.然后我们才能够通过这个地址向服务器特定的应用程序发送信息.对于网络上的 ...