Mathematics:Raising Modulo Numbers(POJ 1995)

              

              阶乘总和

  题目大意:要你算一堆阶乘对m的模...

  大水题,对指数二分就可以了。。。

  

 1 #include <iostream>
 2 #include <functional>
 3 #include <algorithm>
 4 
 5 using namespace std;
 6 
 7 typedef long long LL_INT;
 8 
 9 LL_INT cal(const LL_INT, const LL_INT, const LL_INT);
10 
11 int main(void)
12 {
13     int case_sum, item_sum;
14     LL_INT mod, a, b, sum;
15     scanf("%d", &case_sum);
16 
17     while (case_sum--)
18     {
19         sum = 0;
20         scanf("%lld%d", &mod, &item_sum);
21         for (int i = 0; i < item_sum; i++)
22         {
23             scanf("%lld%lld", &a, &b);
24             sum = (sum + cal(a, b, mod)) % mod;
25         }
26         printf("%lld
", sum);
27     }
28     return 0;
29 }
30 
31 LL_INT cal(const LL_INT coe, const LL_INT pow, const LL_INT mod)
32 {
33     LL_INT x, y;
34     if (!pow)
35         return 1;
36     x = cal(coe, pow >> 1, mod);
37     y = (x*x) % mod;
38 
39     if (pow % 2)
40         y = (coe*y) % mod;
41     return y;
42 }

原文地址:https://www.cnblogs.com/Philip-Tell-Truth/p/5023366.html