模拟
link
纯纯规律大模拟
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+9;
void moyuhualuo(){
int n,m; cin>>n>>m;
int c1=m,c0=n-m;
string s;
for(int i=1;i<=n;i++){
if(i%3==1){
if(c1>0){
c1--;
s+='1';
}else {
c0--;
s+='0';
}
}else{
if(c0>0){
c0--;
s+='0';
}else{
c1--;
s+='1';
}
}
}
//cout<<s<<endl;
int ans=0;
for(int i=0;i+2<n;i++){
int res=0;
for(int j=i;j<=i+2;j++){
if(s[j]=='1') res++;
else res--;
}
if(res>0) ans++;
}
cout<<ans;
}
int main( )
{
cin.tie(nullptr)->sync_with_stdio(false);
moyuhualuo();
return 0;
}
逆元板子题
link
学习逆元可以先学习快速幂原理,python是自带快速幂和逆元的
第一个放在那里无影响,
期望:
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+9;
const ll p=1e9+7;
ll qpow(ll a,ll b){
ll ans=1;
while(b){
if(b&1) ans=ans*a%p;
a=a*a%p;
b>>=1;
}
return ans;
}
void moyuhualuo(){
ll n; cin>>n;
cout<<(6*n-12)*qpow(n-1,p-2)%p;
//逆元/费马小定律
}
int main( )
{
cin.tie(nullptr)->sync_with_stdio(false);
moyuhualuo();
return 0;
}