Algorithm


Problem Name: beecrowd | 1145

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1145

Logical Sequence 2

 

Adapted by Neilor Tonin, URI Brazil

Timelimit: 1

Write an program that reads two numbers X and Y (X < Y). After this, show a sequence of 1 to y, passing to the next line to each X numbers.

 

Input

 

The input contains two integer numbers X (1 < X < 20) and Y (X < Y < 100000).

 

Output

 

Each sequence must be printed in one line, with a blank space between each number, like the following example.

 

 

 

Input Sample Output Sample

3 99

1 2 3
4 5 6
7 8 9
10 11 12
...
97 98 99

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming


#include <bits/stdc++.h>

using namespace std;

int main(){
    int x, y;
    cin >> x >> y;
    int cnt = 0;
    for (int i = 1; i  < = y; i++){
        cnt += 1;
        if (cnt == x){
            cout << i << endl;
            cnt = 0;
        }
        else{
            cout << i << " ";
        }
    }
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3 99

Output

x
+
cmd
1 2 3 4 5 6 7 8 9 10 11 12 ... 97 98 99

#2 Code Example with Java Programming

Code - Java Programming


import java.io.IOException;
import java.util.Scanner;

public class Main{
    public static void main(String[] args) throws IOException{
        Scanner input = new Scanner(System.in);
        int x = input.nextInt();
        int y = input.nextInt();
        int cnt = 0;
        for (int i = 1; i  < = y; i++){
            cnt += 1;
            if (cnt == x){
                System.out.println(i);
                cnt = 0;
            }
            else{
                System.out.printf("%d ", i);
            }
        }
    }
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3 99

Output

x
+
cmd
1 2 3 4 5 6 7 8 9 10 11 12 ... 97 98 99

#3 Code Example with Javascript Programming

Code - Javascript Programming


var input = require('fs').readFileSync('/dev/stdin', 'utf8');
// var lines = input.split('\n');
var sep = [' ', '\n'];
// console.log(separators.join('|'));
var line = input.split(new RegExp(sep.join('|'), 'g'));

var x = parseInt(line.shift());
var y = parseInt(line.shift());

var cnt = 0;

for (var i = 1; i  < = y; i++){
    cnt += 1;
    if (cnt == x){
        console.log(i);
        cnt = 0;
    }
    else{
        process.stdout.write(i+ " ");
    }
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3 99

Output

x
+
cmd
1 2 3 4 5 6 7 8 9 10 11 12 ... 97 98 99

#4 Code Example with Python Programming

Code - Python Programming


x, y = map(int, input().split(" "))

cnt = 0

for i in range(1, y+1):
    cnt += 1
    if (cnt == x):
        print(i)
        cnt = 0
    else:
        print(i, end=" ")
Copy The Code & Try With Live Editor

Input

x
+
cmd
3 99

Output

x
+
cmd
1 2 3 4 5 6 7 8 9 10 11 12 ... 97 98 99
Advertisements

Demonstration


Previous
#1144 Beecrowd Online Judge Solution 1144 Logical Sequence Solution in C++, Java, Js and Python
Next
#1146 Beecrowd Online Judge Solution 1146 Growing Sequences Solution in C++, Java, Js and Python