mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-11-06 06:43:49 +00:00
fix(P7990.cpp): 修复比较运算符缺少const修饰符的问题
feat(yacs101.cpp): 添加新题目解法,计算奇偶数乘积 refactor(P1495.cpp): 移除未使用的扩展欧几里得算法实现 refactor(P3811.cpp): 重构模逆元计算,使用扩展欧几里得算法
This commit is contained in:
parent
03f57b7619
commit
c96882f67e
@ -12,7 +12,7 @@ const ll maxn = 2e5+5;
|
||||
ll k,m,n,f[maxn],l[maxn],r[maxn];
|
||||
struct C{
|
||||
ll p,t;
|
||||
inline bool operator<(const C& o){
|
||||
inline bool operator<(const C& o)const{
|
||||
return p<o.p;
|
||||
}
|
||||
}c[maxn];
|
||||
|
||||
15
src/10/27/yacs101.cpp
Normal file
15
src/10/27/yacs101.cpp
Normal 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";
|
||||
}
|
||||
@ -1,38 +1,7 @@
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
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(){
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,21 +1,29 @@
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <istream>
|
||||
|
||||
using ll = int64_t;
|
||||
|
||||
const ll maxn=3e6+5;
|
||||
ll inv[maxn];
|
||||
ll n,p;
|
||||
|
||||
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(){
|
||||
std::iostream::sync_with_stdio(false);
|
||||
std::cout.tie(nullptr);
|
||||
ll n,p;
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
std::cin>>n>>p;
|
||||
inv[1]=1;
|
||||
std::cout<<1<<'\n';
|
||||
for(ll i{2};i<=n;i++){
|
||||
inv[i]=(p-p/i)*inv[p%i]%p;
|
||||
std::cout<<inv[i]<<'\n';
|
||||
for(ll i=1;i<=n;i++){
|
||||
ll x,y;
|
||||
exgcd(i, p, x, y);
|
||||
std::cout<<(x%p+p)%p<<"\n";
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user