Algorithm


Problem Name: beecrowd | 1144

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

Logical Sequence

 

Adapted by Neilor Tonin, URI Brazil

Timelimit: 1

Write a program that reads an integer N. N * 2 lines must be printed by this program according to the example below. For numbers with more than 6 digits, all digits must be printed (no cientific notation allowed).

 

Input

 

The input file contains an integer N (1 < N < 1000).

 

Output

 

Print the output according to the given example.

 

 

 

Input Sample Output Sample

5

1 1 1
1 2 2
2 4 8
2 5 9
3 9 27
3 10 28
4 16 64
4 17 65
5 25 125
5 26 126

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming


#include <bits/stdc++.h>

using namespace std;

int main(){
    int num;
    cin >> num;
    for (int i = 1; i  < = num; i++){
        cout << i << " " << (i * i) << " " << (i * i * i) << endl;
        cout << i << " " << (i * i) + 1 << " " << (i * i * i) + 1 << endl;
    }
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
5

Output

x
+
cmd
1 1 1 1 2 2 2 4 8 2 5 9 3 9 27 3 10 28 4 16 64 4 17 65 5 25 125 5 26 126

#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 num = input.nextInt();
        for (int i = 1; i  < = num; i++){
            System.out.printf("%d %d %d\n", i, (i * i), (i * i * i));
            System.out.printf("%d %d %d\n", i, (i * i) + 1, (i * i * i) + 1);
        }
    }
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
5

Output

x
+
cmd
1 1 1 1 2 2 2 4 8 2 5 9 3 9 27 3 10 28 4 16 64 4 17 65 5 25 125 5 26 126

#3 Code Example with Javascript Programming

Code - Javascript Programming


var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');

var num = parseInt(lines.shift());

for (var i = 1; i  < = num; i++){
    console.log(i +" "+ (i * i) +" "+ (i * i * i));
    console.log(i +" "+ ((i * i) + 1) +" "+ ((i * i * i) + 1));
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
5

Output

x
+
cmd
1 1 1 1 2 2 2 4 8 2 5 9 3 9 27 3 10 28 4 16 64 4 17 65 5 25 125 5 26 126

#4 Code Example with Python Programming

Code - Python Programming


num = int(input())

for i in range(1, num+1):
    print(f"{i} {i * i} {i * i * i}")
    print(f"{i} {(i * i) + 1} {(i * i * i) + 1}")
Copy The Code & Try With Live Editor

Input

x
+
cmd
5

Output

x
+
cmd
1 1 1 1 2 2 2 4 8 2 5 9 3 9 27 3 10 28 4 16 64 4 17 65 5 25 125 5 26 126
Advertisements

Demonstration


Previous
#1143 Beecrowd Online Judge Solution 1143 Squared and Cubic Solution in C++, Java, Js and Python
Next
#1145 Beecrowd Online Judge Solution 1145 Logical Sequence 2 Solution in C++, Java, Js and Python