Codeforces 327C Magic Five & Code

Source: Internet
Author: User
Tags pow

Actually, it's very watery. "Does not
The code is not long anyway

Ideas:
For a string, it is easy to know that for a certain I is 0 or 5, there is a 2^i "string starting from No. 0, the first bit OK"
A string of selection is also very easy to find, in order to find out each of the selected method, add up "set a string has a K-type selection method
For multiple strings, the second string of one I "for the first bit of the string" has 2^ (strlen (s) +i) selection, that is (2^i) x (2^strlen (s)) species selection method. In this case, the sum of the selected method can be extracted as (2^strlen (s)) K selection method
In this case, the sum of the selection of the M string can be sorted into the sum of the geometric progression, and the geometric progression formula is ai=k (2^ (strlen (s) x (i-1)))
According to the geometric progression summation formula we get M-string and tm= (1-2^ (strlen (s) *m))/(1-2^strlen (s))%mod

And then the math formula is done.
Division modulo = = Well, the first reaction is to find the inverse ... On the method of solving the inverse element I just forgot to "check it Out", Fermat's Little's theorem to find a inverse B:
Ab≡1 (mod p)
a^ (p-1) ≡1 (mod p) "P is prime"
Inverse b is a^ (p-2), very witty transformation

Fast power to seek TM

No more.

* * Less modulo a few times WA several, and then look at the data found that they have calculated a negative response to come up

 #include <iostream> #include <stdio.h> #include <string.h> #define MOD
1000000007 #define LL-long long using namespace std;
int k,l,x,y;
LL CNT;
String A;
    ll Pow (ll A,ll b) {ll r=1;
        while (b) {if (b&1) R*=a,r%=mod;
        A*=a,a%=mod;
    b>>=1;
} return R;
    int main (void) {cin>>a>>k;
    L=a.size ();
    for (int i=0;i<l;i++) if (a[i]== ' 0 ' | | | | a[i]== ' 5 ') Cnt+=pow (2,i), cnt%=mod;
    X=pow (2,l);
    Y=pow (X,K);
    X= ((1-x)%mod+mod)%mod;
    Y= ((1-y)%mod+mod)%mod;
    cout<< (cnt* (Y*pow (x,mod-2))%mod)%mod<<endl;
return 0; }

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.