# Cf 327c against RMB

Source: Internet
Author: User
`/* Find the rule first and find the rule formula. The formula is S * (2 ^ (M * k)-1)/(2 ^ s-1), and then the modulo needs to be continuously obtained, then, when the denominator is obtained, the reverse element is obtained based on the tip horse theorem. * // * Inverse element: ferma's theorem: If (A, P) is mutually qualitative and P is a prime number: Then a ^ (p-1) = 1 (% P) so the inverse element of A is X = a ^ (P-2) (% P) */# include <iostream> # include <cstring> # include <cstdio> # define Mo 1000000007 # define int _ int64 // This is a bit difficult to understand. This takes a long time, you cannot place int64 in every value of Mian. Using namespace STD; char a ;/* int fastmi (int A, int B) {int r = 1; int base = A; while (B! = 0) {If (B & 1) r = (R * base) % Mo; base = (base * base) % Mo; B >>= 1 ;} return R;} fast power: A number & 1 depends on the last digit after the number is converted into binary. Divide 11 by 2 and get 11 1101 r = 2, base = 2 ^ 2; 5 1001 r = 2 ^ 3, base = 2 ^ 4; 2 10 base = 2 ^ 8; 1 01 R = 2 ^ 11; 0 */INT fastmi (int A, int N) {If (n = 0) return 1; else if (N % 2 = 1) Return (A * fastmi (A, n-1) % Mo; else {int temp = fastmi (A, n/2 ); return (temp * temp) % Mo ;}} void main () {int I, S, K; while (CIN> A) {S = 0; int M = strlen (a); for (I = 0; I <m; I ++) if (A [I] = '0' | A [I] = '5') S = (S + fastmi (2, I) % Mo; scanf ("% i64d", & K); Int x = fastmi (2, m); int P = fastmi (x, k); P = (p-1 + Mo) % Mo; S = (S * P) % Mo; X = (X-1 + Mo) % Mo; X = fastmi (x, Mo-2) % Mo; // X is the inverse element of the denominator X to the MO, the Application of tip horse theorem. S = (S * X) % Mo; printf ("% i64d \ n", S);} return ;}`

Related Keywords:

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.