随笔分类 - 数论
前缀和
摘要:什么是前缀和 原数组: a[1], a[2], a[3], a[4], a[5], …, a[n]前缀和 Si为数组的前 i项和前缀和: S[i] = a[1] + a[2] + a[3] + … + a[i] 注意: 前缀和的下标一定要从 1开始, 避免进行下标的转换 #include "iost
阅读全文
埃式筛法
摘要://将一个大小为n的数组a置为1,枚举n以内的每个数, 将以其倍数为下标的位置置为0,最终a数组内为1的位 置下标为质数,正确性由质数的定义可知。#include<bits/stdc++.h> using namespace std; bool a[100000]; int main() { lon
阅读全文
gcd
摘要:求最大公因数 #include<bits/stdc++.h> using namespace std; int gcd(int a,int b){ if(b==0) return a; return (b,a%b); } void exgcd(int a,int b,int &d,int &x,in
阅读全文
快速幂模板
摘要:#include<bits/stdc++.h> using namespace std; //推荐写第一种 第二种是递归写法 int quickpower(int a,int b,int n) { int ret=1; while(b) { if(b%2==1) ret=ret*a%n; a=a*a
阅读全文