#题面 传送门 #题意 输入正整数a1,a2,a3..an和模m,求a1a2...an mod m #Sol 首先有$$ ab\equiv \begin a^{b%\phi(p)}gcd(a,p)=1\ a^b~~~gcd(a,p)\neq1,b<\phi(p)\ a^{b%\phi(p)+\phi(p)}gcd(a,p)\neq1,b\geq\phi(p) \end(modp)

\[ 递归处理,每次取$\varphi$,可以试乘来判断是否会大于$\varphi$大于时加上就好了 ```cpp # include <bits/stdc++.h> # define RG register # define IL inline # define Fill(a, b) memset(a, b, sizeof(a)) using namespace std; typedef long long ll; IL ll Read(){ RG ll x = 0, z = 1; RG char c = getchar(); for(; c < '0' || c > '9'; c = getchar()){ if(c == '#') exit(0); z = c == '-' ? -1 : 1; } for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); return x * z; } int n, m, a[20]; IL int Phi(RG int x){ RG int cnt = x; for(RG int i = 2; i * i <= x; ++i){ if(x % i) continue; while(!(x % i)) x /= i; cnt -= cnt / i; } if(x > 1) cnt -= cnt / x; return cnt; } IL int Pow(RG ll x, RG ll y, RG ll p){ RG int flg2 = 0, flg1 = 0; RG ll cnt = 1; for(; y; y >>= 1){ if(y & 1) flg1 |= (cnt * x >= p || flg2), cnt = cnt * x % p; flg2 |= (x * x >= p); x = x * x % p; } return cnt + flg1 * p; } IL int Calc(RG int x, RG int p){ if(x == n) return Pow(a[x], 1, p); return Pow(a[x], Calc(x + 1, Phi(p)), p); } int main(RG int argc, RG char* argv[]){ for(RG int Case = 1; ; ++Case){ m = Read(); n = Read(); printf("Case #%d: ", Case); for(RG int i = 1; i <= n; ++i) a[i] = Read(); printf("%d\n", Calc(1, m) % m); } return 0; } ``` \]

相关文章:

  • 2022-01-30
  • 2021-05-31
  • 2022-12-23
  • 2021-10-05
  • 2021-09-10
  • 2021-11-05
  • 2022-12-23
  • 2021-09-19
猜你喜欢
  • 2022-12-23
  • 2021-12-21
  • 2021-08-27
  • 2021-07-22
  • 2021-08-16
  • 2021-09-11
  • 2021-07-10
相关资源
相似解决方案