Cattle passenger train 54 - B

/*2019-11-16


 

Problem Description

After a little learning Fenwick tree, very interested lowbit, then out of a question.
Given non-negative integer n. Note lowbit (x) indicates a value corresponding to a least significant bit of x under the binary,
e.g., a minimum number of bits x 1, 2, 3, respectively, at the first position, lowbit (x) is 1, 2, respectively, 4. Seeking sumΣ (i = 0,2 ^ n) lowbit (i).
The output result 998 244 353 modulo answers. T set of data.
Input Description:
The first line an integer T, denotes the number of data sets.
Next, a T lines each integer n, as shown in the meanings described in the title.
Output Description: The
output of the T represents the result of each inquiry.
Example 1
Input
2
2
. 4
outputs
. 8
48
explained
when n = 2, Ans = sumΣ ( i = 0,4) lowbit (i) = 0 + 1 + 2 + 1 + 4 = 8.
Remarks
T <= 3 * 10 ^ 5 , n≤10 ^ 18.
Enter the amount of data that may be larger, it is recommended to use a faster way to read
* /



/ *
Outline of Solution:
ANS = (n-+. 1) * 2 ^ (n--. 1) ^ 2 + (. 1-n-) = (+ n-2) * 2 ^ (n--. 1);
first 0 ~ 2 ^ n odd bit least significant bit represents the value 1, is a summation sum1 = 1 * 2 ^ (n -1)
to look at the value of the minimum number of bits represented by an even bit, it can be found in each of the n = 1 ~ n, 2 ^ n the left and right, the least significant bit value of 1 are symmetrically summation sum2 = (n-1) * 2 ^ (n-1) + 2 ^ n = (n + 1) * 2 ^ (n -1)
* /

 

1  @ 1: Since n <= 10 ^ 18, can be read directly% lld (long long, -2 ^ 63-1 ~ 2 ^ 63-1; unsigned long long, 0 ~ 2 ^ 64-1- ^ ------ 18 is far greater than 10) 
2 #include <bits / STDC ++ H.>
 . 3  the using  namespace STD;
 . 4 typedef Long  Long LL;
 . 5  const  int MOD = 998 244 353 ;
 . 6  LL fastpow (A LL, LL n- )
 . 7  {
 . 8      LL B = A, = RES . 1 ;
 . 9      the while (n-) {
 10          IF (& n- . 1 ) RES = (B * RES)% MOD;
 . 11          B = (B * B)% MOD;
 12 is         n>>=1;
13     }
14     return res;
15 }
16 int main()
17 {
18     int T;
19     scanf("%d", &T);
20     while (T--){
21         ll n;
22         scanf("%lld",&n);
23         if(n==0){
24             printf("%lld\n", 1);
25             continue;
26         }
27          ll tem=fastpow(2,n-1);
28         n=(n+2)%mod;
29         printf("%lld\n",(n*tem)%mod);
30     }
31     return 0;
32 }

 

 1 //拓展,n>=10^18;用数组读入 
 2 #include<bits/stdc++.h>
 3 using namespace std;
 4 typedef long long ll;
 5 const int mod=998244353;
 6 ll fastpow(ll a,ll n)
 7 {
 8     ll b=a,res=1;
 9     while(n){
10         if(n&1) res=(b*res)%mod;
11         b=(b*b)%mod;
12         n>>=1;
13     }
14     return res;
15 }
16 int main()
17 {
18     ll T;
19     scanf("%lld",&T);
20     while(T--){
21         ll n=0,cnt=0;
22         char s[20];
23         scanf("%s",s);
24         int le=strlen(s);
25         if(le==1&&s[0]=='0'){
26             printf("1\n");
27             continue;
28         }
29         int i=0;
30         while(le--){
31             n=n*10+s[i++]-'0';
32             if(n>=mod) cnt=cnt*10+(int)(n/mod);
33             else cnt=cnt*10;
34             n%=mod;
35         }
 36          II ans = 1 ;
37          if (cnt) {
 38              ll tem = 0 ;
39              TEM fastpow = ( 2 , v);
40              ans = fastpow (TEM, cnt- 1 );
41              if (n == 0 ) = ans (ANS * TEM / 2 )% v;
42              presence ans = ans * tem% v;
43          }
 44          if (n) {
 45              ll fastpow tmp = ( 2 , n- 1 );
46             years = years *% tmp mod;
47          }
 48          years = (* years (n + 2 )% mod)% mod;
49          printf ( " % lld \ n " , year);
50      }
 51      return  0 ;
52 }

As well as to expand after a write

 

Guess you like

Origin www.cnblogs.com/littleyyhome/p/11873058.html