This commit is contained in:
Zengtudor 2024-08-07 11:26:16 +08:00
parent d3292ba39e
commit 3cd3abd251
3 changed files with 78 additions and 1 deletions

2
.gitignore vendored
View File

@ -50,3 +50,5 @@ day4/U287193/chat
day4/U461920/fixed day4/U461920/fixed
day5/hard/hard day5/hard/hard
day5/perfect/perfect day5/perfect/perfect
day5/good/good
day5/fair/fair

View File

@ -44,7 +44,27 @@ int main(){
## Day5 ## Day5
### 需要学习的点 ### 需要学习的点
>区间最值 #### 区间最值
#### 弄懂分数取模出现很大的数字是什么鬼、
1. >费马小定理
2. >逆元
```cpp
// a/b%M
ll _ksm(ll a, ll b,ll M){
ll res = 1;
while(b) {
if(b & 1)
res = res * a % M;
a = a * a % M;
b >>= 1;
}
return res;
}
ll ksm(ll a,ll b,ll M){
return a * _ksm(b, M - 2,M) % M;
}
```
# 排序 # 排序
## 稳定性 ## 稳定性

55
day5/fair/fair.cpp Normal file
View File

@ -0,0 +1,55 @@
#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define PRINT_VALUE(v){cout<<#v<<" :"<<(v)<<endl;}
#endif
#ifndef DEBUG
#define PRINT_VALUE(v)
#endif
#define ll long long
#define int long long
ll _ksm(ll a, ll b,ll M){
ll res = 1;
while(b) {
if(b & 1)
res = res * a % M;
a = a * a % M;
b >>= 1;
}
return res;
}
ll ksm(ll a,ll b,ll M){
return a * _ksm(b, M - 2,M) % M;
}
int n,k,m,times=1,b;
signed main(){
cin>>n>>k>>m;
b=k;
/*
x=k+x/b
bx=k*b+x
(b-1)x=k*b
x=(k*b)/(b-1)
*/
PRINT_VALUE(b);
PRINT_VALUE(n);
PRINT_VALUE(b<n);
while(b<n){
PRINT_VALUE(b<n);
PRINT_VALUE(b*k);
b=b*k;
times++;
PRINT_VALUE(times);
}
PRINT_VALUE(k);
PRINT_VALUE(b);
PRINT_VALUE(ksm(k*b,b-1,m));
cout<<ksm(k*b,b-1,m)<<endl;
}