Dreamoon and Sets CodeForces - 476D(规律,思路题)



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

1 1

Output

5
1 2 3 5
Input2 2Output222 4 6 2214 18 10 16Note

For the first example it's easy to see that set {1, 2, 3, 4} isn't a valid set of rank 1 since .

一题找规律的题,开始也不会做,同学教我的,

每一行找互质的最小数字就得了

1 2 3 5

7 8 9 11

13 14 15 17

。。。。。。

。。。。。。

x     x +1    x+2    x+4(x要是奇数才行)

代码:

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<set>
using namespace std;
int main()
{
    int n,m;
    while(~scanf("%d%d",&n,&m))
    {
        printf("%d\n",(6*n-1)*m);
        for(int i=1;i<=m;i++){
            printf("%d ",(6*i-5)*m);
            printf("%d ",(6*i-4)*m);
            printf("%d ",(6*i-3)*m);
            printf("%d\n",(6*i-1)*m);
        }
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值