D. Dreamoon and Sets (Codeforces Round #273 ),

Source: Internet
Author: User

D. Dreamoon and Sets (Codeforces Round #273 ),
D. Dreamoon and Setstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Dreamoon likes to play with sets, integers and. is defined as the largest positive integer that divides bothAAndB.

LetSBe a set of exactly four distinct integers greater than 0. DefineSTo be of rankKIf and only if for all pairs of distinct elementsSI,SJFromS,.

GivenKAndN, Dreamoon wants to make upNSets of rankKUsing integers from 1MSuch that no integer is used in two different sets (of course you can leave some integers without use). Calculate the minimumMThat makes it possible and print one possible solution.

Input

The single line of the input contains two space separated integersN,K(1 digit ≤ DigitNLimit ≤ limit 10 0000000, limit 1 limit ≤ limitKLimit ≤ limit 100 ).

Output

On the first line print a single integer-the minimal possibleM.

On each of the nextNLines print four space separated integers representingI-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 minimalM, Print any one of them.

Sample test (s) input
1 1
Output
51 2 3 5
Input
2 2
Output
222 4 6 2214 18 10 16
Note

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


Construct, when k is equal to 1, push several groups of data, such as 1, 2, 3, 5; 7, 8, 9, 11; 13, 14, 15, 17;,; 25, 26, 27,29. We will find thatIs a cycle, and multiplying the number in each cycle by k will make the maximum number of common dikes in the cycle is k.


Code:

#include <cstdio>#include <iostream>#include <cstring>using namespace std;int main(){    int n, k;    scanf("%d %d", &n, &k);    int a = 1, b = 2, c = 3, d = 5;    printf("%d\n", (d * k + 6 * k * (n- 1)));    a*=k;    b*=k;    c*=k;    d*=k;    for(int i = 0; i < n; i++)    {        printf("%d %d %d %d\n",a, b, c, d);        a += 6 * k;        b += 6 * k;        c += 6 * k;        d += 6 * k;    }}




How can codeforces change the id color)

It's not Beijing time. It's four hours later. The color is not clear. I only know that 200 or 300 is blue.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.