2019 meter preliminaries garlic Road 3 D. Alibaba help battle SARS (difficult) (+ Remainder of large numbers Euler descending)

Alibaba help battle SARS (difficult)

  • 33.29%
  •  1000ms
  •  262144K
 

At present, the SARS virus in the world, discovered by scientists, a single strand of the virus and its variants of DNA, cytosine, thymine are paired. Although this is a major discovery, but not the most important feature of the virus, because this feature is too weak.

In order to find out the characteristics of the virus, CN Centers for Disease Control and Alibaba Group cooperation, with the power of thinking and procedures of science and technology to solve this problem. Alibaba now appoint you a special SARS senior fellow at the CN Center for Disease Control to study in this feature may be the number of DNA sequence of the SARS virus. More precisely, you need to count all the following conditions are satisfied length  n number n of the string:

  1. Only strings of A, T, C, G composition
  2. A occurs even number of times (or may not occur)
  3. C occurs even number of times (or may not appear)

When  n-2 = n- = 2, all the following conditions are satisfied string  . 6 6:

TT,TG,GT,GG,AA,CC。

NOTE: Since this number can be very large, you only need to give  10 ^ 9 + 7 . 1 0 9 + result modulo to 7.

Input Format

A plurality of input document gives  n- n-. Finally digit  0 zero terminated.

Output Format

For each input file  n number n, the output character string satisfying the condition of  10 ^ 9 + 7 . 1 0 9 + 7 modulo results.

data range

n \ 10 ^ {(10 ^ 5)} n 1 0 ( 1 0 5 )

Sample input

1
2
3
100
0

Sample Output

2 
. 6 
20 is 
113 046 907 




to find the law run again using dfs: 2 ^ n + 4 ^ n
then processing large numbers is modulo, the string is read Fermat's little theorem + Euler descending.
Form similar HDU - 4704 sum to take large numbers of more than + Euler descending


#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;

char s[100005];

ll qMod(ll a,ll b){
    ll ans=1;
    a%=MOD;
    while(b){
        if(b&1) ans=ans*a%MOD;
        b>>=1;
        a=a*a%MOD;
    }
    return ans;
}
int main()
{
    int n,len,i;
    while(scanf(" %s",s)&&s[0]!='0'){
        ll c=0;
        len=strlen(s);
        for(i=0;i<len;i++){
            int x=s[i]-'0';
            c=c*10+x;
            if(c>1000000006) c%=1000000006;
        }
        c=((c-1)%1000000006+1000000006)%1000000006;
        printf("%lld\n",(qMod(2,c)+qMod(4,c))%MOD);
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/yzm10/p/10963618.html