14 条题解
-
2
分治
#include<bits/stdc++.h> using namespace std; const int N=1e5+5,INF=0x3f3f3f3f; typedef long long LL; typedef unsigned long long ULL; ULL a,b,p; ULL f(ULL a,ULL b){ if(b==0)return 1%p; if(b==1)return a%p; if(b&1)return a*f(a*a%p,b/2)%p; return f(a*a%p,b/2)%p; } int main() { cin>>a>>b>>p; cout<<f(a,b)%p; return 0; }
-
1
`#include<bits/stdc++.h> using namespace std; const int N=1e5+5,INF=0x3f3f3f3f; typedef long long LL; typedef unsigned long long ULL; ULL a,b,p; ULL f(ULL a,ULL b){ if(b0)return 1%p; if(b1)return a%p; if(b&1)return af(aa%p,b/2)%p; return f(a*a%p,b/2)%p; } int main() { cin>>a>>b>>p; cout<<f(a,b)%p; return 0; }
`
-
0
#include<bits/stdc++.h> using namespace std; #define LL long long const int N = 1e5 + 10; const int INF = 0x3f3f3f3f; long long power( long long n , long long m , long long p ) { if ( n == 0 ) { return 0; } long long ans = 1; while ( m ) { if ( m & 1 ) { ans = ( ans * n ) % p; } m >>= 1; n = ( n * n ) % p; } return ans % p; } int main() { long long n , m , p; cin >> n >> m >> p; cout << power( n , m , p ); return 0; } //菜鸟驿站 //老六专属
-
0
#include<bits/stdc++.h> using namespace std; #define LL long long const int N = 1e5 + 10; const int INF = 0x3f3f3f3f; long long power( long long n , long long m , long long p ) { if ( n == 0 ) { return 0; } long long ans = 1; while ( m ) { if ( m & 1 ) { ans = ( ans * n ) % p; } m >>= 1; n = ( n * n ) % p; } return ans % p; } int main() { long long n , m , p; cin >> n >> m >> p; cout << power( n , m , p ); return 0; } //菜鸟驿站 //老六专属
-
0
cpp ``` #include <bits/stdc++.h> using namespace std; #define LL long long const int N = 1e5 + 10; const int INF = 0x3f3f3f3f; long long power( long long n , long long m , long long p ) { if ( n == 0 ) { return 0; } long long ans = 1; while ( m ) { if ( m & 1 ) { ans = ( ans * n ) % p; } m >>= 1; n = ( n * n ) % p; } return ans % p; } int main() { long long n , m , p; cin >> n >> m >> p; cout << power( n , m , p ); return 0; } //菜鸟驿站 //老六专属 ```
-
-1
#include #include
include
#include #include #include #include const int N=1e2+10; const int INF =0x3f3f3f3f; using namespace std; unsigned long long a,b,p; int power(int a,int b,int p){ long long ans=1; long long wq=a; while(b){ if(b&1){ ans=ans*wq%p;
} b>>=1; wq=wq*wq%p; } return ans %p;
} int main(){ cin>>a>>b>>p; cout<<power(a,b,p); }
-
-3
知识点:快速幂
/* int %o/%lo(八进制) %d/%i/%ld/%li(十进制) %x/%lx(十六进制)[如标名为o/lo/d/i/lo/li/x/lx即输出为八进制/十进制/十六进制] longlong %lld float %f/%e double %lf/%le char %c char[] %s 'a'=97 'z'=122 'A'=65 'Z'=90 '0'=48 '9'=57 */ #include <iostream> #include <iomanip> #include <cmath> #include <cstdio> #include <cstring> #include <algorithm> #include <ctime> #include <limits> #include <assert.h> #include <stdlib.h> using namespace std; #define LL long long #define ull unsigned long long const int N=1e5+10; const int INF=0x3f3f3f3f; const double pi=3.1416; LL a,b,p; long long power(long long a,long long b,long long p){ long long ans=1; long long wp=a; while(b){ if(b&1){ ans=ans*wp%p; } b>>=1; wp=wp*wp%p; } return ans%p; } int main(){ cin>>a>>b>>p; cout<<power(a,b,p)<<endl; return 0; }
-
-4
/***************************************** 备注:数学nanhai 5 ******************************************/ #include <queue> #include <math.h> #include <stack> #include <stdio.h> #include <iostream> #include <vector> #include <iomanip> #include <string.h> #include <algorithm> using namespace std; #define LL long long const int N = 1e5 + 10; const int INF = 0x3f3f3f3f; LL power(LL n , LL m , LL p) { if(n == 0) return 0; LL ans = 1; while(m) { if(m&1) ans = (ans * n) %p; m >>= 1; n = (n*n)%p; } return ans%p; } int main() { LL n , m , p; cin >> n >> m >> p; cout << power(n , m , p); return 0; }
- 1
信息
- ID
- 2
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 8
- 标签
- 递交数
- 3219
- 已通过
- 490
- 上传者