Jishou big school race A SARS virus (Euler descending)

Links: https://ac.nowcoder.com/acm/contest/925/A
Source: Cattle-off network

Title Description

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 of the following conditions is the number of length n 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, all the following conditions are satisfied string 6:

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

Note: Because this number can be very large, you can just give the results of the 10 ^ 9 + 7 modulo.

Enter a description:

Multiple sets of input (not more than 10 groups), each line an integer n-: 0 <n-< 10 10 . 5 10105

Output Description:

To 10 ^ 9 +7 result modulo the number of input files for each of n, satisfying the condition of the output string.
Example 1

Entry

copy
1
2
100

Export

copy
2 
. 6 
113 046 907 



that Italy: meet the sequence number of the number of topics
ideas: we have to calculate the number of the number of the end of each letter, we can be divided into two categories ((T, G), ( A, C)), T, G letters at the end of every one of us will turn twice, a, C double letters every two months, but in fact we are a, C at the end we can put T, G, T, G at the end, too, so
Suppose the AC [] at the end is AC TG [] at the end is TG
the AC [n-] = the AC [n--2] * 2 + TG [n--2] * 2;
TG [n-] = the AC [n--. 1] * 2 + TG [n-1] * 2 ;
Finally, we can simplify the equation equals (2 ^ (n-1)
) * (2 ^ (n-1) +1) because our n particularly large, I use here the Euler descending
(a ^ n)% mod = (a ^ (b% phi (mod) + mod))% mod
#include<bits/stdc++.h>
#define maxn 1000005
#define mod 1000000007
using namespace std;
typedef long long ll;
char str[maxn];
ll big_number(char s[],ll m){
    ll num=0;
    for(int i=0;s[i]!='\0';i++){
        num=num*10+(s[i]-'0');
        num%=m;
    }
    return num;
}
ll quick_pow(ll x,ll y){
    ll ans=1;
    while(y){
        if(y&1) ans=(ans*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return ans;
} 
int main(){
    while(cin>>str)
    {
        int flag=0;
        if((str[strlen(str)-1]-'0')%2) flag=1;
        ll num=big_number(str,mod-1); 
        //cout<<"num:"<<num<<endl;
        ll da=quick_pow(2,num-1+mod-1);
        //if(flag%2) da=(da*2)%mod;
        cout<<(da*(da+1))%mod<<"\n";
    }
}

 

Guess you like

Origin www.cnblogs.com/Lis-/p/11072032.html