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