Algorithm
Problem Name: 2 AD-HOC - beecrowd | 2229
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2229
Folding
By OBI - Olimpíada Brasileira de Informática 2002 Brazil
Timelimit: 1
Zezinho has Artistic Initiation classes at his school, and recently learned how to make paper folding. He was fascinated by the many possibilities of folding a single sheet of paper. As Zezinho very fond of mathematics, he decided to invent a puzzle involving folding. Zezinho defines a folding operation D consisting of folding twice a square sheet of paper in order to achieve a square with 1/4 of original size, as shown in Fig.
After repeating N times this folding operation D on paper, Zezinho cut the resulting square with a vertical section and a horizontal section, as shown below.
Zezinho then challenged his colleagues, who guesses how many pieces of paper were produced?
Input
The input consists of several test sets. Each test set consists of a single line containing an integer N (-1 ≤ N ≤ 15) indicating the number of times folding operation D was applied. The end of the input is indicated by N = -1.
Output
For each entry test set your program should produce three lines in the output. The first line should contain a test set identifier in the format "Teste n", where n is numbered from 1. The second line should contain the number of pieces of paper obtained after cutting folding calculated by your program. The third line should be left blank. The spelling shown in Example output below should be followed strictly.
Input Sample | Output Sample |
1 0 -1 |
Teste 1 9 Teste 2 4 |
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <cstdio>
int main() {
int n, teste = 1;
while (scanf("%d", &n) && (n + 1)) {
int inteiro = ((1 << n) + 1);
inteiro *= inteiro;
printf("Teste %d\n%d\n\n", teste++, inteiro);
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
0
-1
Output
9
Teste 2
4