Problem description We need to find the number (including the natural number N of the input) with the following number of properties ). Enter a natural number n (n <= 1000), and then process the natural number as follows:
No processing;
Add a natural number to its left, but the natural number cannot exceed half of the original number;
After adding the number, continue to follow this rule until the natural number cannot be added. Input The input contains multiple groups of data, each of which is a natural number of N. Output The number of data outputs in each group that meet the conditions. Sample Input
6
Sample output
The number of 6 hint conditions is 6, 16, 26,126, 36,136.
Author Hynu
Code:
// Recursive formula: H (I) = H (I-1) When I is an odd number; H (I) = H (I-1) When I is an even number) + H (I/2 ). # include <stdio. h> int H [1001]; int fun (int n) {int I; H [1] = 1; for (I = 2; I <= N; I ++) {if (I % 2 = 1) h [I] = H [I-1]; else h [I] = H [I-1] + H [I/2];} return H [N] ;}int main () {int N; while (scanf ("% d", & N )! = EOF) {printf ("% d \ n", fun (N) ;}return 0 ;}