exCRT & 骆克强乘法
exCRT & 骆克强乘法
只是丢两个板子啦。
exCRT的做法就是每次拿两个方程合并成一个,合并的过程推下式子就是个 exgcd。具体可以在 zjk 的 ptt 里面找到。
先放个 $ O(1) $ 慢速乘
ll mul( ll a , ll b , ll p ) { a %= p , b %= p; return ( (a * b - (ll)( (ll)( (long double)a / p * b + 0.5 ) * p )) % p + p ) % p; }
然后一个 exgcd
void exgcd( ll a , ll b , ll& d , ll& x , ll& y ) {
if( !b ) { d = a , x = 1 , y = 0; return; }
else exgcd( b , a % b , d , y , x ) , y -= x * ( a / b );
}
最后是 excrt
Luogu 板子题和 PTT 上的 ab 居然是反着的。。。毒瘤
#include "iostream"
#include "algorithm"
#include "cstring"
#include "cstdio"
using namespace std;
#define MAXN 100006
typedef long long ll;
ll mul( ll a , ll b , ll p ) { a %= p , b %= p; return ( (a * b - (ll)( (ll)( (long double)a / p * b + 0.5 ) * p )) % p + p ) % p; }
int n;
ll A[MAXN] , B[MAXN];
ll gcd( int a , int b ) { return b ? a : gcd( b , a % b ); }
void exgcd( ll a , ll b , ll& d , ll& x , ll& y ) {
if( !b ) { d = a , x = 1 , y = 0; return; }
else exgcd( b , a % b , d , y , x ) , y -= x * ( a / b );
}
bool crt( ll& a1 , ll a2 , ll& b1 , ll b2 ) {
ll d = a2 - a1;
ll g , k1 , k2;
exgcd( b1 , b2 , g , k1 , k2 );
if( d % g ) return 0;
else {
ll r = b2 / g;
k1 = mul( k1 , d / g , r );
a1 = k1 * b1 + a1;
b1 = ( b1 * r );
return 1;
}
}
ll excrt( ) {
ll a1 = A[0] , b1 = B[0] , a2 , b2;
for( int i = 1 ; i < n ; ++ i ) {
a2 = A[i] , b2 = B[i];
if( !crt( a1 , a2 , b1 , b2 ) ) return -1;
}
return a1;
}
int main() {
cin >> n;
for( int i = 0 ; i < n ; ++ i ) scanf("%lld%lld",&B[i],&A[i]);
cout << excrt( ) << endl;
}
exCRT & 骆克强乘法的更多相关文章
- Data-independent acquisition mass spectrometry in metaproteomics of gut microbiota - implementation and computational analysis DIA技术在肠道宏蛋白质组研究中的方法实现和数据分析 (解读人:闫克强)
文献名:Data-independent acquisition mass spectrometry in metaproteomics of gut microbiota - implementat ...
- Fast and accurate bacterial species identification in urine specimens using LC-MS/MS mass spectrometry and machine learning (解读人:闫克强)
文献名:Fast and accurate bacterial species identification in urine specimens using LC-MS/MS mass spectr ...
- 解读人:闫克强,Metabolic and gut microbial characterization of obesity-prone mice under high-fat diet(高脂饮食下易胖倾向小鼠的代谢和肠道微生物菌群特征分析)
单位: 上海中医药大学 蚌埠医学院 上海交通大学附属第六人民医院 夏威夷大学癌症中心 第二军医大学 技术:非靶向代谢组学,16S rRNA测序技术 一. 概述: 本研究对小鼠进行高脂饮食,根据体重增长 ...
- 洛谷4245:【模板】任意模数NTT——题解
https://www.luogu.org/problemnew/show/P4245 给两个多项式,求其乘积,每个系数对p取模. 参考: 代码与部分理解参考https://www.luogu.org ...
- 李洪强iOS经典面试题上
李洪强iOS经典面试题上 1. 风格纠错题 修改完的代码: 修改方法有很多种,现给出一种做示例: // .h文件 // http://weibo.com/luohanchenyilong/ / ...
- 【学习笔记】OI模板整理
CSP2019前夕整理一下模板,顺便供之后使用 0. 非算法内容 0.1. 读入优化 描述: 使用getchar()实现的读入优化. 代码: inline int read() { int x=0; ...
- [转] ACM中国国家集训队论文集目录(1999-2009)
国家集训队1999论文集 陈宏:<数据结构的选择与算法效率——从IOI98试题PICTURE谈起>来煜坤:<把握本质,灵活运用——动态规划的深入探讨>齐鑫:<搜索方法中的 ...
- NOI 国家集训队论文集
鉴于大家都在找这些神牛的论文.我就转载了这篇论文合集 国家集训队论文分类 组合数学 计数与统计 2001 - 符文杰:<Pólya原理及其应用> 2003 - 许智磊:<浅谈补集转化 ...
- ACM/IOI 历年国家集训队论文集和论文算法分类整理
国家集训队1999论文集 陈宏:<数据结构的选择与算法效率--从IOI98试题PICTURE谈起> 来煜坤:<把握本质,灵活运用--动态规划的深入探讨> 齐鑫:<搜索方法 ...
随机推荐
- 脚本注入2(post)
终于写到非get类型的注入了. 不过,我懒得在这里搞代码审计了:留到存储型XSS原型的时候再来分析源码吧. 这次以Less-15为例. 框里随便输点东西,submit,抓包,发现包出现了一些改变: 同 ...
- (三)、Docker常用基础命令
1.Docker 帮助命令 帮助命令: docker version 查看版本 docker info 查询docker详细信息 docker --help 查看命令帮助 2.Docker 镜像命令 ...
- 热身训练2 The All-purpose Zero
The All-purpose Zero 简要题意: 长度为n的数组,每个数字为S[i],$0$是一种很神奇的数字,你想要的,它都可以变! 问这个序列的最长上升子序列长度为多少? 分析: 我们将除了 ...
- 色彩滤镜矩阵(Color Filter Array)
数码相机上的每个象素都带有一个光感应器,用以测量光线的明亮程度.由于光电二极管是只支持单颜色的装置,它不能区别不同波长的光线.因此,数码相机工程师在相机感应器的上部装上了一套镶嵌式的颜色滤镜,一个颜色 ...
- Python课程笔记(八)
一些简单的文件操作,学过linux的话理解感觉不会很难.课程代码 一.OS 目录方法 这个模块提供了一种方便的使用操作系统函数的方法 函数 说明 os.mkdir("path") ...
- path-sum-ii leetcode C++
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given su ...
- swagger3.0(springboot)消除basic-error-controller
1.新建springboot项目,可以通过https://start.spring.io/快速生成springboot项目. 2.引入jar依赖: <dependency> <gro ...
- Centos7 升级过内核 boot分区无法挂载修
参考连接:https://www.cnblogs.com/heqiuyong/p/11186301.html 故障图 挂载系统盘,光盘启动,急救模式, chroot /mnt/sysimage 报错 ...
- 一文读懂什么是渲染管线(7k字)
01 | 渲染基础 渲染(Render)定义 渲染在电脑绘图中是指软件从模型生成图像的过程,通俗讲就是在计算机里面给虚拟世界"拍照".渲染主要分为两种,一种是预渲染(pre-ren ...
- 【Java】IO流
File类 介绍 File类的一个对象,代表一个文件或一个文件目录 File类声明在java.io包下 File类中涉及关于文件或文件目录的创建.删除.重命名.修改时间.文件大小等方法,并未涉及到写入 ...