Description
A number sequence is defined as following:
S (1) = 1,
S (2) = 11,
S (3) = 21,
S (4) = 1211,
S (5) = 111221,
S (6) = 312211,
......
Now, we need you to calculate the length of S (n).
Input
The input consists of multiple test cases. Each test case contains one integers n.
(1<=n<=30)
N=0 signal the end of input.
Output
Length of S (n).
Sample Input
2
5
0
Sample Output
2
6
Reference code:
1 //Local Play Table2#include <iostream>3#include <cstdio>4#include <cmath>5#include <ctype.h>6#include <cstring>7#include <algorithm>8#include <string>9 using namespacestd;Ten #defineM 10000 + 500 One Chara[ -][m]; A intb[ -]; - intMain () - { theFreopen ("In.txt","R", stdin); - intt,i,j; -a[0][0] ='1'; -a[0][1] =' /'; +b[0] =1; - for(i =0; I < to; i + +) + { A intCNT =0, t =0; at Chartemp = a[i][0]; - for(j =0; A[I][J]! =' /'; J + +) - { - if(temp = =A[i][j]) - - { in while(temp = =A[i][j]) - { toJ + +; +CNT + +; - } the } *A[i +1][t + +] = cnt +'0'; $A[i +1][t + +] =temp;Panax Notoginsengtemp =A[i][j]; -CNT =0; theJ--; + } AA[i +1][T] =' /'; the } + for(inti =0; I < to; i + +) -printf"%d,", strlen (A[i])); $ intIU; $ while(SCANF ("%d", &iu) &&IU) -printf"%d\n", B[iu]); - return 0; the}
1#include <iostream>2#include <cstdio>3#include <cmath>4#include <ctype.h>5#include <cstring>6#include <algorithm>7#include <string>8 using namespacestd;9 #defineM 10000 + 500Ten intb[ -] = {1,2,2,4,6,6,8,Ten, -, -, -, the, $, +, +,102,134,176,226,302,408,528,678,904,1182,1540, -,2606,3410,4462,5808}; One intMain () A { - //freopen ("In.txt", "R", stdin); - inti; the while(SCANF ("%d", &i) &&i) -printf"%d\n", B[i-1]); - return 0; -}
Length of S (n)