Algorithm


Problem Name: beecrowd | 2028

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

Sequence of Sequence

 

By Albertinin Mourato, UFPE BR Brazil

Timelimit: 3

Hyam is a guy that loves sequences. He is finding interesting sequences that even Fibonacci would not have imagined. One day Hyam saw that given a number N, he could make a sequence like 0 1 2 2 3 3 3 4 4 4 …N N N … N. However, Hyam saw that each value that increased in the sequence number, the total quantity increases at a factorial rate. In this case, instead of multiplying, you add the total number of numbers to the sequence with the value of the next number in the sequence. For example, if N = 2. The correct sequence would be 0 1 2 2, which is 4 digits. Now, if N = 3, the next number in the sequence would have the value 3, so the total quantity of numbers in the sequence would bem the quantiy of numbers with N = 2, which is 4, plus the value of the next number in the sequence, in this case 3, giving you 7, since the correct sequence for N = 3 is 0 1 2 2 3 3 3.

Your task is make an algorithm that given a integer N, has as answer the total quantity of numbers of this sequence and below the complete sequence.

 

Input

 

The input consists of several test cases. Each case is composed of an integer N (0 <= N <= 200) that indicates the last value of the last N numbers of the sequence numbers.
The input ends with end of file (EOF).

 

Output

 

The output is in format Case X: N numbers where X is the order of number of cases and N is the number of numbers that contains the complete sequence, the next line sequence numbers with a space between them. You are asked to leave a blank line after each case.

 

 

 

Input Sample Output Sample

0

1

2

3

Caso 1: 1 numero

0


Caso 2: 2 numeros

0 1


Caso 3: 4 numeros

0 1 2 2


Caso 4: 7 numeros

0 1 2 2 3 3 3

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include<stdio.h>
int main()
{
    int a,b,c = 1,d = 1,i,j,k,l;
    while(scanf("%d",&a)!=EOF)
    {
        d=1;
        for(k = 0; k  < = a; k++){
            for(l = 0; l  <  k; l++){
                d++;
            }
        }
        if(d==1){
            printf("Caso %d: %d numero\n",c,d);
        }
        else{
        printf("Caso %d: %d numeros\n",c,d);
        }
        for(i = 0; i <= a; i++)
        {
            if(i == 0)
                b = -1;
            else
                b = 0;
            for(j = b;  j  <  i; j++)
            {
                if(i == a && j == i-1){
                    printf("%d\n",i);
                }
                else{
                printf("%d ",i);
                }
            }
        }
    c++;
    printf("\n">;
    }
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
0 1 2 3

Output

x
+
cmd
Caso 1: 1 numero 0 Caso 2: 2 numeros 0 1 Caso 3: 4 numeros 0 1 2 2 Caso 4: 7 numeros 0 1 2 2 3 3 3

#2 Code Example with C++ Programming

Code - C++ Programming


#include <bits/stdc++.h>

using namespace std;


int main(){
  int n, c = 1;
  while(cin >> n)
  {
    vector<int> print;
    print.push_back(0);
    for(int i = 0; i  < = n; ++i)
    {
      for(int j = 0; j  <  i; ++j)
      {
        print.push_back(i);
      }
    }
    if(print.size() == 1)
      printf("Caso %d: %d numero\n", c++, 1);
    else
      printf("Caso %d: %d numeros\n", c++, print.size());
    printf("%d", print[0]);
    for(int i = 1; i < print.size(); ++i)
    {
      printf(" %d", print[i]);
    }
    printf("\n\n">;
  }
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
0 1 2 3

Output

x
+
cmd
Caso 1: 1 numero 0 Caso 2: 2 numeros 0 1 Caso 3: 4 numeros 0 1 2 2 Caso 4: 7 numeros 0 1 2 2 3 3 3

#3 Code Example with Javascript Programming

Code - Javascript Programming


var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');
var prompt = function(texto) { return lines.shift();};
for (let cases = 1; true; cases++) {
  var number = parseInt(prompt());
  if (isNaN(number)) {
    break;
  }

  var sequence = [0];

  for (let i = 1; i  < = number; i++) {
    for (let n = 0; n  <  i; n++) {
      sequence.push(i);
    }
  }

  if (sequence.length == 1) {
    console.log("Caso " + cases + ": " + sequence.length + " numero");
  } else {
    console.log("Caso " + cases + ": " + sequence.length + " numeros");
  }
  console.log(sequence.join(" "));
  console.log("");
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
0 1 2 3

Output

x
+
cmd
Caso 1: 1 numero 0 Caso 2: 2 numeros 0 1 Caso 3: 4 numeros 0 1 2 2 Caso 4: 7 numeros 0 1 2 2 3 3 3
Advertisements

Demonstration


Previous
#1015 Beecrowd Online Judge Solution 1015 Distance Between Two Points Solution in C, C++, Java, Python and C#
Next
#2029 Beecrowd Online Judge Solution 2029 Honey Reservoir Solution in C, C++, Java, Js and Python