B. Dreamoon and Sets
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

The single line of the input contains two space separated integers n, k (1 ≤ n ≤ 10 000, 1 ≤ k ≤ 100).

Output

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.

Sample test(s)
Input
1 1
Output
5
1 2 3 5
Input
2 2
Output
22
2 4 6 22
14 18 10 16
Note

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)(数论)的更多相关文章

  1. 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 ...

  2. codeforces 477B B. Dreamoon and Sets(构造)

    题目链接: B. Dreamoon and Sets time limit per test 1 second memory limit per test 256 megabytes input st ...

  3. Codeforces Round #272 (Div. 2) D. Dreamoon and Sets 构造

    D. Dreamoon and Sets 题目连接: http://www.codeforces.com/contest/476/problem/D Description Dreamoon like ...

  4. CF 984C Finite or not? (数论)

    CF 984C Finite or not? (数论) 给定T(T<=1e5)组数据,每组数据给出十进制表示下的整数p,q,b,求问p/q在b进制意义下是否是有限小数. 首先我们先把p/q约分一 ...

  5. 【CODEFORCES】 B. Dreamoon and Sets

    B. Dreamoon and Sets time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. 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 ...

  7. 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 ...

  8. cf 450b 矩阵快速幂(数论取模 一大坑点啊)

    Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, ple ...

  9. cf 645F Cowslip Collections 组合数学 + 简单数论

    http://codeforces.com/contest/645/problem/F F. Cowslip Collections time limit per test 8 seconds mem ...

随机推荐

  1. Eclipse中新建WEB项目,JSP页面报错。

    在Eclipse中新建java web项目,在JSP页面的第一行提示这个错误: [The superclass "javax.servlet.http.HttpServlet" w ...

  2. shell脚本批量ping测试IP是否通

    #!/bin/bash rm -f result.txt cat ip.txt | fping > result.txt 2行代码就搞定,很方便,初学shell,很强大,问了下同事,但是shel ...

  3. JDBC操作Oracle数据库——实际操作过程中的小总结

    1.对数据库中,表的每一行数据记录的增删改查 增:insert into 表名 values() 删:delete 表名 where 条件(id=?) 改:update 表名 set 列名=? whe ...

  4. javascript权威指南笔记--javascript语言核心(三)

    1.var用来声明一个或多个变量.全局变量是全局对象的属性,它无法通过delete删除. 如果var语句中的变量没有指定初始化表达式,那么这个变量的初始值为undefined. 变量声明语句会被提前到 ...

  5. Python基础学习笔记(一)入门

    参考资料: 1. <Python基础教程> 2. http://www.runoob.com/python/python-chinese-encoding.html 3. http://w ...

  6. FLASH CC 2015 CANVAS 实际应用过程中遇到的【粉色】问题(不定期更新)

    1,导入音乐导致发布卡死 一开始以为是不支持,FQ搜索了一些帖子,也有说不能再时间轴加音乐,需要用代码加入,想想不太可能啊,如果真的不能为什么IDE不禁用呢? 而实际问题是: 我使用的其中一条音效有问 ...

  7. MYSQL 表级锁 行级锁 页面锁区别

    myisam存储引擎默认是表级锁 innodb存储引擎默认是行级锁 DBD存储引擎默认是页面锁   表级锁:开销小,加锁快:不会出现死锁:锁定粒度大,发出锁冲突的概率最高,并发度最低.行级锁:开锁大, ...

  8. shiro连接数据库

    建一个jdbcRealm.ini [main] jdbcRealm=org.apache.shiro.realm.jdbc.JdbcRealm dataSource=com.mchange.v2.c3 ...

  9. jj前端项目1th总结

    1:设计图--->分出几个独立模块--->颗粒化布局--->文档流控制整体布局--->固定位置的元素绝对定位,段落这种元素不可绝对定位.----->加上和后台交互用的js ...

  10. Android 让输入框输入指定字符的办法

    让输入框输入指定字符的办法 有一个需求 让输入密码的时候只能输入数字字母可见字符 不能输入中文 之前还以为要写代码 还来发现有一个属性可以直接实现 <EditText android:layou ...