Cf 272b. Dima and Sequence

Source: Internet
Author: User
You can go to CF to find the question.
Analysis process:
If it is an even number, it is directly equal to dividing by 2, for example, F (8) = f (4) = F (2) = F (1)
If it is an odd number, add 1 after dividing by 2 directly, for example, F (1) = f (0) + 1 = 0 + 1 = 1
It can be proved that the Left and Right numbers can be continuously divided by 2, and the formula is obtained: F (0) + x = x.
So what is X?
First, we can see through observation that as long as it is a number larger than 1, after dividing by 2, we can get 1 at last, whether it is an odd or even number.
Second, we can see through the formula that if it is an even number, it is like 8. After dividing it by 2, it will not increase the value of X. Only after dividing the odd number by 2, the remainder 1 will be added to X outside function f. Therefore, the key to the problem is: divide the original one until the division is zero, the total number of vendors (including the original number) is an odd number.
Then, if a number passes through to obtain the simplest constant, if it is the same, it means F (a) = F (B). Finally, as long as we look at the computed series, number of occurrences of each number. The number of identical pairs is calculated by means of permutation and combination.
Code As follows:
 // B // By Molly # include 
  
    # include 
   
     using namespace STD; const int n = 100010; typedef long ll; ll N, seq [N], num [40], K; int main () {While (CIN> N) {for (INT I = 0; I 
    
      seq [I]; while (SEQ [I]) {If (SEQ [I] % 2 = 1) K ++; seq [I]/= 2;} num [k] ++;} ll ans = 0; for (INT I = 1; I <34; ++ I) {ans + = num [I] * (Num [I]-1)/2 ;} cout 
     
    
   
  

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.