fix(P7990.cpp): 修复比较运算符缺少const修饰符的问题

feat(yacs101.cpp): 添加新题目解法,计算奇偶数乘积
refactor(P1495.cpp): 移除未使用的扩展欧几里得算法实现
refactor(P3811.cpp): 重构模逆元计算,使用扩展欧几里得算法
This commit is contained in:
Zengtudor 2025-10-27 14:41:23 +08:00
parent 03f57b7619
commit c96882f67e
4 changed files with 34 additions and 42 deletions

View File

@ -12,7 +12,7 @@ const ll maxn = 2e5+5;
ll k,m,n,f[maxn],l[maxn],r[maxn]; ll k,m,n,f[maxn],l[maxn],r[maxn];
struct C{ struct C{
ll p,t; ll p,t;
inline bool operator<(const C& o){ inline bool operator<(const C& o)const{
return p<o.p; return p<o.p;
} }
}c[maxn]; }c[maxn];

15
src/10/27/yacs101.cpp Normal file
View File

@ -0,0 +1,15 @@
#include <cstdint>
#include <iostream>
#include <istream>
using ll = int64_t;
ll n,one,two;
int main(){
std::iostream::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin>>n;
for(ll i=1;i<=n;i++)one+=i&1,two+=!(i&1);
std::cout<<one*two<<"\n";
}

View File

@ -1,38 +1,7 @@
#include <cstdint> #include <cstdint>
#include <iostream>
#include <tuple>
#include <vector>
using ll = int64_t; using ll = int64_t;
std::tuple<ll,ll,ll> exgcd(const ll &a,const ll &b){
if(b==0){
ll x=1,y=0;
return std::make_tuple(a,x,y);
}
auto[d,x,y] = exgcd(b, a%b);
const ll tmpy = y;
y=x-a/b*y;
x=tmpy;
return std::make_tuple(d,x,y);
}
ll inv(const ll &n,const ll &p){
auto[d,x,y]=exgcd(n, p);
x=(x%p+p)%p;
return x;
}
int main(){ int main(){
ll N;
std::cin>>N;
std::vector<ll> p(N),n(N);
for(ll i{0};i<N;i++){
std::cin>>p[i]>>n[i];
}
ll prod{1};
for(ll pi:p){
prod=prod*pi;
}
} }

View File

@ -1,21 +1,29 @@
#include <cstdint> #include <cstdint>
#include <iostream> #include <iostream>
#include <istream> #include <istream>
using ll = int64_t; using ll = int64_t;
const ll maxn=3e6+5; ll n,p;
ll inv[maxn];
static inline ll exgcd(ll a,ll b,ll&x,ll&y){
if(b==0){
x=1;
y=0;
return a;
}
ll gcd=exgcd(b, a%b, y, x);
y-=a/b*x;
return gcd;
}
int main(){ int main(){
std::iostream::sync_with_stdio(false); std::iostream::sync_with_stdio(false);
std::cout.tie(nullptr); std::cin.tie(nullptr);
ll n,p;
std::cin>>n>>p; std::cin>>n>>p;
inv[1]=1; for(ll i=1;i<=n;i++){
std::cout<<1<<'\n'; ll x,y;
for(ll i{2};i<=n;i++){ exgcd(i, p, x, y);
inv[i]=(p-p/i)*inv[p%i]%p; std::cout<<(x%p+p)%p<<"\n";
std::cout<<inv[i]<<'\n';
} }
} }