🐖数学及数论等算法
文章平均质量分 61
再见
风骨散人Chiam
我叫风骨散人Chiam,名字的意思是向往可以不低头的自由生活,可现实却不是这样,希望同样被生活绑架的你,可以通过自己的努力改变现状。目前在中国科学院攻读研究生,研究方向是网络安全和控制访问,热爱编程,热爱技术,喜欢分享,知识无界,希望我的分享可以帮到你!
如果有什么想看的,可以私信我,如果在能力范围内,我会发布相应的博文!
感谢大家的阅读!你的点赞、收藏、关注是对我最大的鼓励!
在CSDN没什么收益,博主已经没有动力继续更新技术文章了,已经准备跑路了,大家如果想了解我的更改情况就去我的主页看看。
展开
-
矩阵快速幂--HDU 6030 Happy Necklace
Problem DescriptionLittle Q wants to buy a necklace for his girlfriend. Necklaces are single strings composed of multiple red and blue beads.Little Q desperately wants to impress his girlfriend, he ...原创 2020-04-22 11:47:16 · 2726 阅读 · 0 评论 -
数论--HDU 1495 非常可乐
Description大家一定觉的运动以后喝可乐是一件很惬意的事情,但是seeyou却不这么认为。因为每次当seeyou买了可乐以后,阿牛就要求和seeyou一起分享这一瓶可乐,而且一定要喝的和seeyou一样多。但seeyou的手中只有两个杯子,它们的容量分别是N 毫升和M 毫升 可乐的体积为S (S<101)毫升 (正好装满一瓶) ,它们三个之间可以相互倒可乐 (都是没有刻度的,且 S...原创 2020-04-22 11:40:34 · 2727 阅读 · 0 评论 -
Codeforce-Ozon Tech Challenge 2020-C. Kuroni and Impossible Calculation(鸽笼原理)
To become the king of Codeforces, Kuroni has to solve the following problem.He is given n numbers a1,a2,…,an. Help Kuroni to calculate ∏1≤i<j≤n|ai−aj|. As result can be very big, output it modulo ...原创 2020-03-05 22:32:31 · 2692 阅读 · 0 评论 -
Codeforce-CodeCraft-20 (Div. 2)-C. Primitive Primes(本原多项式+数学推导)
It is Professor R’s last class of his teaching career. Every time Professor R taught a class, he gave a special problem for the students to solve. You being his favourite student, put your heart into ...原创 2020-03-05 23:12:02 · 2686 阅读 · 6 评论 -
数学--数论--广义欧拉降幂(模板)
未使用欧拉筛:适用于较少次数计算的欧拉降幂。#include <bits/stdc++.h>#define ll long longusing namespace std;ll a,m,b;inline ll read(ll m){ register ll x=0,f=0;char ch=getchar(); while(!isdigit(ch)) ch=...原创 2020-03-02 00:23:35 · 2762 阅读 · 0 评论 -
数学--数论--因子和线性筛 (模板)
#include <bits/stdc++.h>using namespace std;typedef long long ll;#define N 500022int prime[N],cnt;bool vis[N];int num[N],e[N];void init(){ for(int i=2;i<=N;++i) { if(!...原创 2020-02-08 03:06:26 · 2694 阅读 · 0 评论 -
数学--数论--随机算法--Pollard Rho 大数分解算法(纯模板带输出)
#include <bits/stdc++.h>using namespace std;typedef long long ll;ll pr;ll pmod(ll a, ll b, ll p) { return (a * b - (ll)((long double)a / p * b) * p + p) % p; } //普通的快速乘会Tll gmod(ll a, ll b,...原创 2020-02-08 01:57:30 · 2774 阅读 · 2 评论 -
数学--数论--快速幂--最大公约数--位运算模板
inline ll gcd(ll a,ll b){//听说二进制算法特快 if(!a)return b; if(!b)return a; int t=ctz(a|b); a>>=ctz(a); do{ b>>=ctz(b); if(a>b){ll t=b;b=a,a=t;} b-=...原创 2020-01-26 01:04:04 · 2766 阅读 · 0 评论 -
线性筛求积性函数的模板
void sieve(){ tot = 1; memset(vis, 0, sizeof(vis)); low[1] = 1; G[1] = 函数G(n) n=1时的定义 for (int i = 2; i <= mxn; i++) { if (!vis[i]) { pri[tot++]...原创 2020-01-21 01:25:02 · 2692 阅读 · 0 评论 -
数学--图论--莫比乌斯线性筛模板
int prime[MAXN],prime_tot;bool isprime[MAXN];int mu[MAXN];void pre_calc(int limt){ mu[1]=1; for(int i=2;i<=limt;i++) { if(!isprime[i]){ prime[prime_tot]=i; ...原创 2020-01-16 15:49:01 · 2648 阅读 · 0 评论 -
数学--数论---欧拉筛 模板
typedef long long ll;bool ok[maxn];int prime[maxn],phi[maxn],cnt;void sieve(){ phi[1]=1; for(ll i=2;i<maxn;++i) { if(!ok[i]) { prime[cnt++]=i; phi[i]=i-1; } for(int j=0...原创 2020-01-16 09:09:19 · 2654 阅读 · 0 评论 -
数学--数论--素数
定义判断:bool isPrime (int n){ for(int i=2;i*i<=n;i++) { if(n%i==0) return false; } else return false;}埃氏筛法int primes[N],cnt;bool bprime[N];void getPrime(int n){ memset(bprime,false,s...原创 2019-12-17 11:57:25 · 2678 阅读 · 0 评论 -
数论--费马小定理求逆元
int Fermat_inverse(int a,int mod){ int res = 1; for(int i = 1;i < mod - 1;++i) res *= a; return res; } //如果p为大素数,我们可以用快速幂求解,时间复杂度为:long long fast_pow_mod(long long a,long long b,l...原创 2019-12-09 20:00:37 · 2682 阅读 · 0 评论 -
数论--模板整理
数论–康托展开与逆康托展开模板数学–数论–组合数(卢卡斯+扩展卢卡斯)模板数学–数论–Miller_Rabin判断素数数论–中国剩余定理模板数学–数论–逆元(拓展欧几里得)模板...原创 2019-12-09 19:59:29 · 2539 阅读 · 0 评论 -
数论--康托展开与逆康托展开模板
#include<bits/stdc++.h>using namespace std;const int MAX = 13;int Fac[MAX],N;//求出阶乘void init(){ Fac[0] = 1; for(int i=1;i<=N;++i){ Fac[i] = Fac[i-1]*i; }}//康托展开in...原创 2019-12-09 19:55:58 · 2846 阅读 · 0 评论 -
数学--数论--组合数(卢卡斯+扩展卢卡斯)模板
#include<cstdio>const int N = 2000 + 5;const int MOD = (int)1e9 + 7;int comb[N][N];//comb[n][m]就是C(n,m)void init(){ for(int i = 0; i < N; i ++){ comb[i][0] = comb[i][i] = 1; ...原创 2019-12-07 14:25:55 · 2684 阅读 · 0 评论 -
数学--数论--Miller_Rabin判断素数
#include<iostream>#include<algorithm>#include<cstring>#include<cstdlib>#include<cmath>#include<ctime>using namespace std;typedef long long ll;const int N = ...原创 2019-12-06 20:25:59 · 2720 阅读 · 0 评论 -
数论--中国剩余定理模板
void exgcd(int a,int b,int &x,int &y){ if(b==0){ x=1; y=0; return;} exgcd(b,a%b,x,y); int tp=x; x=y; y=tp-a/b*y;}int china(){ int ans=0,lcm=1,x,y; for(int i=1;i<...原创 2019-12-06 20:01:35 · 2660 阅读 · 0 评论 -
CF思维联系– CodeForces -CodeForces - 992C Nastya and a Wardrobe(欧拉降幂+快速幂)
Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in t...原创 2020-03-02 00:16:44 · 2647 阅读 · 0 评论 -
数学--数论--欧拉降幂和广义欧拉降幂(实用好理解)
先摆上公式:ab≡{abmodϕ(p)gcd(a,p)=1abgcd(a,p)≠1,b<ϕ(p)abmodϕ(p)+ϕ(p)gcd(a,p)≠1,b≥ϕ(p) (modp)a^{b} \equiv \begin{cases}a^{bmod\phi (p)} & \text gcd(a,p)=1 \\ a^b & \text ...原创 2020-03-01 23:05:36 · 2684 阅读 · 0 评论 -
数学--数论--欧拉降幂--P5091 欧拉定理
题目背景 出题人也想写有趣的题面,可惜并没有能力。 题目描述 给你三个正整数,a,m,ba,m,ba,m,b,你需要求:ab mod ma^b \bmod mabmodm 输入格式 一行三个整数,a,m,ba,m,ba,m,b 输出格式 一个整数表示答案 输入输出样例 输入 #1 复制 2 7 4 输出 #1 复制 2输入 #2 复制 9...原创 2020-03-01 23:07:16 · 2725 阅读 · 0 评论 -
数学--数论-- AtCoder Beginner Contest 151(组合数+数学推导)好题(๑•̀ㅂ•́)و✧
思路统计最大值出现的次数,和最小值出现的次数。虽然是每次都是MAX-MIN,我们先求MAX的和,然后再求MIN的和,做差。这次代码写的真的很漂亮题目地址:#include <bits/stdc++.h>using namespace std;template <typename t>void read(t &x){ char ch = ge...原创 2020-02-29 02:39:18 · 2666 阅读 · 1 评论 -
CF思维联系–CodeForces - 223 C Partial Sums(组合数学的先线性递推)
You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that:First we build by the array a an array s of partial sums, ...原创 2020-02-27 00:48:12 · 2658 阅读 · 0 评论 -
数学--组合数学--当C(n,m)中n固定m++的递推模板
ll power(ll a, ll b, ll p){ ll ans = 1 % p; for (; b; b >>= 1) { if (b & 1) ans = ans * a % p; a = a * a % p; } return ans;}long long mm[...原创 2020-02-27 00:36:42 · 2628 阅读 · 0 评论 -
CF思维联系–CodeForces - 222 C Reducing Fractions(数学+有技巧的枚举)
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the frac...原创 2020-02-26 15:15:05 · 2721 阅读 · 0 评论 -
疯子的算法总结(九) 图论中的矩阵应用 Part 1 POJ3613 Cow Relays
图的存储有邻接矩阵,那么他就具备一些矩阵的性质,设有一个图的demo[100][100];那么demo[M][N]就是M—>N的距离,若经过一次松弛操作demo[M][N]=demo[M][K]+demo[K][N],即为demo[M][N]经过了两条条边的最小距离,floyd是 demo[M][N]=Min(demo[M]...原创 2019-08-16 21:14:29 · 2502 阅读 · 0 评论 -
codeforce 227E 矩阵快速幂求斐波那契+N个连续数求最大公约数+斐波那契数列的性质
E. Anniversarytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are less than 60 years left till the 900-th birthday anniversary of a fam...原创 2019-07-27 00:57:29 · 2537 阅读 · 0 评论 -
数学--博弈论--巴什博奕(Bash Game)
终于也轮到我做游戏了,他们做了好几个月的游戏了。巴什博弈:两个人做游戏,取石子,一个人最多可以可以取M个,至少取1个,最后取完的赢。显然,如果n=m+1,那么由于一次最多只能取m个,所以,无论先取者拿走多少个,后取者都能够一次拿走剩余的物品,后者取胜。因此我们发现了如何取胜的法则:如果n=(m+1)r+s,(r为任意自然数,s≤m),那么先取者要拿走s个物品,如果后取者拿走k(≤m)个...原创 2019-11-27 20:53:04 · 3894 阅读 · 0 评论 -
数学--数论--HDU - 6124 Euler theorem (打表找规律)
HazelFan is given two positive integers a,b, and he wants to calculate amodb. But now he forgets the value of b and only remember the value of a, please tell him the number of different possible resul...原创 2020-02-04 20:57:23 · 2605 阅读 · 0 评论 -
数学--数论--Hdu 5793 A Boring Question (打表+逆元)
There are an equation.∑0≤k1,k2,⋯km≤n∏1⩽j<m(kj+1kj)%1000000007=?We define that (kj+1kj)=kj+1!kj!(kj+1−kj)! . And (kj+1kj)=0 while kj+1<kj.You have to get the answer for each n and m that given...原创 2020-01-26 23:23:47 · 2609 阅读 · 0 评论 -
数学--数论--HDU 1098 Ignatius's puzzle (费马小定理+打表)
Ignatius’s puzzleProblem DescriptionIgnatius is poor at math,he falls across a puzzle problem,so he has no choice but to appeal to Eddy. this problem describes that:f(x)=5x13+13*x5+ka*x,input a none...原创 2020-01-26 17:50:12 · 2595 阅读 · 0 评论 -
数学--数论--HDU 4675 GCD of Sequence(莫比乌斯反演+卢卡斯定理求组合数+乘法逆元+快速幂取模)
先放知识点:莫比乌斯反演卢卡斯定理求组合数乘法逆元快速幂取模GCD of Sequence Alice is playing a game with Bob.Alice shows N integers a 1, a 2, …, a N, and M, K. She says each integers 1 ≤ a i ≤ M.And now Alice wants to ask ...原创 2020-01-22 01:21:57 · 2604 阅读 · 0 评论 -
数学--数论--HDU 5223 - GCD
DescribtionIn mathematics, the greatest common divisor (gcd) of two or more integers, when at least one of them is not zero, is the largest positive integer that divides the numbers without a remaind...原创 2020-01-21 17:11:40 · 2684 阅读 · 0 评论 -
数学--数论--HDU 5382 GCD?LCM?(详细推导,不懂打我)
DescribtionFirst we define:(1) lcm(a,b), the least common multiple of two integers a and b, is the smallest positive integer that is divisible by both a and b. for example, lcm(2,3)=6 and lcm(4,6)=1...原创 2020-01-21 01:21:43 · 2627 阅读 · 0 评论 -
积性函数与线性筛
积性函数与线性筛积性函数线性筛素数保证每个数只会被它的最小质因子给筛掉(不同于埃氏筛中每个数会被它所有质因子筛一遍从而使复杂度过高)int pri[N],tot,zhi[N];//zhi[i]为1的表示不是质数void sieve(){ zhi[1]=1; for (int i=2;i<=n;i++) { if (!zhi[i]) pri[...原创 2020-01-20 17:34:48 · 2733 阅读 · 0 评论 -
数学--数论--莫比乌斯反演
一、莫比乌斯反演涉及知识1.莫比乌斯函数2.莫比乌斯的线性筛法3.狄利克雷卷积4.莫比乌斯反演详解5.整除法分块6.杜教筛二、μ 莫比乌斯函数定义μ(n)={1n=1(−1)kn= P1*P2*P3*...*Pk(其中P是质数)0else其他情况μ(n)=\begin{cases}1& \text{n=1}\\(-1)^k& \text{n= P1*P...原创 2020-01-17 17:00:03 · 2720 阅读 · 0 评论 -
数学--数论--HDU 5019 revenge of GCD
Revenge of GCDProblem DescriptionIn mathematics, the greatest common divisor (gcd), also known as the greatest common factor (gcf), highest common factor (hcf), or greatest common measure (gcm), of ...原创 2019-12-21 14:36:52 · 2663 阅读 · 0 评论 -
数学--数论--HDU 2674 沙雕题
WhereIsHeroFrom: Zty, what are you doing ?Zty: I want to calculate N!..WhereIsHeroFrom: So easy! How big N is ?Zty: ...原创 2019-12-20 22:28:02 · 2650 阅读 · 0 评论 -
数学--数论--HDU 2104 丢手绢(离散数学 mod N+ 剩余类 生成元)+(最大公约数)
The Children’s Day has passed for some days .Has you remembered something happened at your childhood? I remembered I often played a game called hide handkerchief with my friends.Now I introduce the g...原创 2019-12-20 10:27:05 · 2719 阅读 · 0 评论 -
数学--数论-- HDU -- 2854 Central Meridian Number (暴力打表)
A Central Meridian (ACM) Number N is a positive integer satisfies that given two positive integers A and B, and among A, B and N, we haveN | ((A^2)*B+1) Then N | (A^2+B)Now, here is a number x, you ...原创 2019-12-19 18:02:21 · 2616 阅读 · 0 评论