Count of numbers: find numbers with the following properties

Source: Internet
Author: User

Topic Overview

We ask to find the number of numbers with the following properties (including the natural number of input n):

First enter a natural number n (n≤1000), and then the natural number is processed according to the following method
1. Not to make any treatment;
2. Add a natural number to the left of it, but the natural number cannot exceed half of the original number;
3. After adding the number, continue to follow this rule until no more natural numbers can be established.

Input

A natural number n.

Output

An integer, the total number.

Ideas for solving problems

I have to say that it is really ... Very good! A chestnut said: if n = 6, there will be the following number of regeneration:

6, 16, 26, 126, 36, 136

Extracts the highest digit x of the current number, which may produce a number of X/2.

Add the final result to the X/2.

Problems encountered

A problem with an AC rate of 83% doesn't seem to run into any problems. 0 0

Source

#include <iostream>  
     
void getnumbers (int n, int& counter) {  
    counter + = N/2;  
    for (int i = 1; I <= N/2 + i) {  
        getnumbers (i, counter);  
    }  
}  
     
int main () {  
    int n = 0, counter = 1;  
     
    Std::cin >> N;  
    Getnumbers (n, counter);  
    Std::cout << counter << Std::endl;  
     
    return 0;  
}

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.