[Problem] The 11th session of the design competition--h. High school Math problems

Source: Internet
Author: User

Title Description

Thinking of solving problems

Can be obtained by the formula: an = 2n + 1, so the problem becomes arithmetic progression or and, this specific why I still can't explain clearly, first dig a hole.

Attached: C + + code

1#include <iostream>2#include <cstdio>3 4 using namespacestd;5 6typedef unsignedLong Longllt;7 8 llt Cal (llt x, Llt D, Llt P, llt Num)9 {TenLLT ret =0; OneRET + = (x/p) *Num; AX%=P; -RET + = (d/p) * num * (num-1) /2; -D%=P; the     if(d * Num + x <P) -         returnret; -     Else -         returnRET + Cal ((d * num + x)% p, p, D, (d * num + x)/P); + } -  + llt My_xor (llt L, Llt R, Llt D) A { atLlt Num = r-l +1; -Llt x = L *2+1; -Llt ans =0, Sum, P =1; -      for(Llt i =1; I <= $; i++) -     { -Sum =Cal (x, D, P, Num); in         if(Sum &1) -Ans + =P; toP <<=1; +     } -     returnans; the } *  $ intMain ()Panax Notoginseng { -     //freopen ("mi.in", "R", stdin); the     //freopen ("H.out", "w", stdout); +     intn, I; A llt L, R, ans; thescanf"%d", &n); +      for(i =1; I <= N; i++) -     { $         //scanf ("%i64d%i64d", &l, &r); $CIN >> L >>R; -Ans = My_xor (l, R,2); -         //printf ("%i64d\n", ans); thecout << ans <<Endl; -     }Wuyi     return 0; the}
View Code

Another way of thinking

This is the official offer of the puzzle.

[Problem] The 11th session of the design competition--h. High school Math problems

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.