![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
专题十四 数论基础
九羽-
日有所进,月有所变,终有所成。
展开
-
Problem A ( 乘法逆元 )
Problem A ( 乘法逆元 )题意:就是给一串数,给一个边界left和right,求从left乘到right的值%9973是多少。思路:维护一个前缀乘积prev,要求[a, b]的hash,只要(prev[b]*inv(prev[a-1]))%mod即可因为前缀乘积要mod9973,所以一定小于9973,而且9973是素数,gcd(prev[a-1],9973)一定等于1...原创 2019-10-16 09:49:00 · 129 阅读 · 0 评论 -
乘法逆元【扩展欧几里得算法】
乘法逆元【扩展欧几里得算法】乘法逆元何为乘法逆元?对于两个数a,p若gcd(a,p)=1则一定存在另一个数b,使得ab ≡ 1( modp ),并称此时的b为a关于1模p的乘法逆元。我们记此时的b为inv(a)或 a−1。举个例子:5×3 ≡ 1( mod14 ) 我们称此时的3为5关于1模14的乘法逆元。如何求乘法逆元?方法一:费马小定理费马小定理:当有两数a...原创 2019-10-16 09:37:13 · 675 阅读 · 0 评论 -
关于青蛙走路问题的理解( 扩展欧几里得的应用 )
关于青蛙走路问题的理解( 扩展欧几里得的应用 )题意是:一只青蛙在数轴的一点0处,他只可以往左跳a米或者b米,或者往右跳a米或者b米。 问这只青蛙能走到哪些点。我们分开来看,先看这只青蛙只能往左往右走a米,得到方程:0 + ax = want1, 这里want1是指只能走a米能到达的点, x是系数可以是任意整数。再看这只青蛙只能往左往右走b米,得到方程:0 + by = w...原创 2019-10-12 21:46:38 · 387 阅读 · 0 评论 -
E - Leading and Trailing ( 快速幂取前3位数 )
E - Leading and Trailing ( 快速幂取前3位数 )You are given two integers: n and k, your task is to find the most significant three digits, and least significant three digits of nk.InputInput starts wit...原创 2019-09-25 09:51:54 · 158 阅读 · 0 评论 -
D - Sigma Function ( 因子和为奇数的特点 )
D - Sigma Function ( 因子和为奇数的特点 )DiscriptionSigma function is an interesting function in Number Theory. It is denoted by the Greek letter Sigma (σ). This function actually denotes the sum of all ...翻译 2019-09-26 11:38:00 · 269 阅读 · 1 评论 -
F - Goldbach`s Conjecture( 素数筛 )
F - Goldbach`s Conjecture( 素数筛 )Goldbach's conjecture is one of the oldest unsolved problems in number theory and in all of mathematics. It states:Every even integer, greater than 2, can be expr...原创 2019-09-26 15:27:56 · 129 阅读 · 0 评论 -
G - Harmonic Number (II) ( 数列求和+找规律 )
G - Harmonic Number (II) ( 数列求和+找规律 )I was trying to solve problem'1234 - Harmonic Number', I wrote the following codelonglongH(intn){ longlongres=0; for(inti=1;i<=n...原创 2019-09-26 16:48:56 · 177 阅读 · 0 评论 -
扩展欧几里德算法详解
扩展欧几里德算法详解扩展欧几里德算法谁是欧几里德?自己百度去先介绍什么叫做欧几里德算法有两个数 a b,现在,我们要求 a b 的最大公约数,怎么求?枚举他们的因子?不现实,当 a b 很大的时候,枚举显得那么的naïve ,那怎么做?欧几里德有个十分又用的定理: gcd(a, b) = gcd(b , a%b) ,这样,我们就可以在几乎是 log 的时间复杂度里求解出来 ...转载 2019-10-09 21:23:47 · 429 阅读 · 2 评论 -
青蛙的约会( 扩展欧几里得 )
青蛙的约会( 扩展欧几里得 )两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面。它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止。可是它们出发之前忘记了一件很重要的事情,既没有问清楚对方的特征,也没有约定见面的具体位置。不过青蛙们都是很乐观的,它们觉得只要一直朝着某个方向跳下去,总能碰到对方的。但是除非这两只青蛙在同一时间跳到同一点上,不然是永远都不...原创 2019-10-11 08:53:50 · 129 阅读 · 0 评论 -
Romantic ( 扩展欧几里得 )
A - Romantic ( 扩展欧几里得 )Girls are clever and bright. In HDU every girl like math. Every girl like to solve math problem!Now tell you two nonnegative integer a and b. Find the nonnegative integer X...原创 2019-10-11 09:41:52 · 152 阅读 · 0 评论 -
J - Prime Game ( 筛素因子 + 思维算贡献 )
J - Prime Game ( 筛素因子 + 思维算贡献 )1.题意:给出n个数字的序列,求:其中:fac(i,j)是指区间[i,j]内数字乘积的素数因子的个数(重复算一个)(有一个小定义是,两个数乘积的素因子就是原来数的素因子,比如12 和 7 素因子分别为{2,3}和{7}, 那么12*7=84的素因子就是{2,3,7} 。)2.思路:因为1<=n&l...转载 2019-09-24 19:44:58 · 298 阅读 · 0 评论 -
C - Aladdin and the Flying Carpet ( 唯一分解定理求因子个数 )
C - Aladdin and the Flying Carpet ( 唯一分解定理求因子个数 )It's said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a powerful Genie. Here we are concerned about th...原创 2019-09-22 14:22:29 · 244 阅读 · 0 评论 -
欧拉定理、拓展欧拉定理及其应用(欧拉降幂法)
欧拉定理、拓展欧拉定理及其应用(欧拉降幂法)摘要 本文主要介绍了数论中的欧拉定理,进而介绍欧拉定理的拓展及应用,结合例题展示如何使用拓展欧拉定理实现降幂取模。 在数论中,欧拉定理,(也称费马-欧拉定理)是一个关于同余的性质定理。了解欧拉定理之前先来看一下费马小定理: a是不能被质数p整除的正整数,则有a^(p-1) ≡ 1 (mod p) 欧拉给出了推广形式...转载 2019-09-03 10:40:10 · 618 阅读 · 0 评论 -
B super_log(找规律 + 欧拉降幂)
B super_log(找规律 + 欧拉降幂)题目链接:https://nanti.jisuanke.com/t/41299题面分析转载自:https://blog.csdn.net/oampamp1/article/details/100191908代码:#include<bits/stdc++.h>using namespace std;#...原创 2019-09-03 21:12:11 · 188 阅读 · 0 评论 -
E - Exponial (欧拉降幂)
E - Exponial (欧拉降幂)题意:如题思路:套欧拉降幂模板。代码:#include<bits/stdc++.h>using namespace std;#define maxn 101010#define MOD(a,b) a>=b?a%b+b:a#define ll long longmap<ll,ll>mp;ll...原创 2019-09-03 21:31:38 · 145 阅读 · 0 评论 -
欧拉降幂模板
#include<bits/stdc++.h>using namespace std;#define maxn 101010#define MOD(a,b) a>=b?a%b+b:a#define ll long longunordered_map<int,int>mp;int n,q,l,r;ll m,w[maxn];ll qpow(ll a,ll...原创 2019-09-04 12:33:37 · 165 阅读 · 0 评论 -
欧拉phi函数—详解
欧拉phi函数—详解原文链接:https://blog.csdn.net/niiick/article/details/81347041翻译 2019-09-05 18:48:04 · 3585 阅读 · 0 评论 -
1到n范围内能被5或6或8整除的数的个数( 容斥 )
1到n范围内能被5或6或8整除的数的个数题目链接:https://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/2543.htmlimport java.util.Scanner;import java.math.*;public class Main { public static v...原创 2019-09-11 11:12:58 · 1267 阅读 · 0 评论 -
J - Floating-Point Hazard ( 微分定义 )
J - Floating-Point Hazard ( 微分定义 )题目链接:https://vjudge.net/problem/2212565/origin题意:求题目给出的公式的值。思路:根据微分的定义。x到x + Δx在此区间内,有函数的增量Δy = f(x + Δx) - f(x),其中 Δx为极小值。Δy又可表示为dy,Δx也可表示为dx。 此题中,y = 所以...原创 2019-09-17 19:54:52 · 189 阅读 · 0 评论 -
A - Bi-shoe and Phi-shoe( 欧拉函数快速筛法 )
A - Bi-shoe and Phi-shoe( 欧拉函数快速筛法 )欧拉函数首先介绍下什么是欧拉函数吧,欧拉函数phi(x)代表小于等于x的数中和x互质的数的个数(小于显然只对1成立), 比如说小于等于9的数中与9互质的有1,2,4,5,7,8,则phi(9)=6.求phi(x)得公式由欧拉给出(神一般的男人,几何学,数论,统计学,物理学,统计学,据说连金融学都有以欧拉命名的公式,...翻译 2019-09-20 21:26:18 · 457 阅读 · 0 评论 -
唯一分解定理 ( 内含 求出n的因子个数)
唯一分解定理一个数n肯定能被分解成 n = . 因为一个数肯定是由合数和质数构成的,合数又可以分解成质数和合数,最后递归下去就会变成质数的乘积。比如36 -> 2*2*3*3 -> .最后化成了质数相乘的形式。(2)中运用等比数列求和公式可化简为:好,现在给出唯一分解定理的两个小应用1. 求出数n的因子个数n = 有一个很简洁的公式: n的因子个...翻译 2019-09-21 21:36:51 · 1301 阅读 · 0 评论 -
K - Keep Your Style ( 排序+数学期望值 )
K - Keep Your Style ( 排序+数学期望值 )题目链接:http://codeforces.com/gym/101845/problem/KThe UNAL programming coaches have lost a bet, they bet the 6 UNAL teams would occupy the first six positions in the...转载 2019-08-30 11:24:06 · 387 阅读 · 0 评论