
ACM_数论
呆雁1707
这个作者很懒,什么都没留下…
展开
-
拓展欧几里得
#include <iostream>#include <cstring>#include <cstdio&a原创 2018-10-25 20:27:15 · 153 阅读 · 0 评论 -
LightOJ - 1234 Harmonic Number(打表+技巧)
原题链接:传送门题意:求调和级数的部分和。调和级数如下:思路:这个题n的数据范围是1e8,直接开数组存不下,可以降值来存,就是每100个数的调和级数存一下。最后再把剩余的遍历一下就好了,时间复杂度也降下来了。#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N = 1e8+...原创 2018-11-27 12:55:39 · 180 阅读 · 0 评论 -
POJ - 2478 Farey Sequence (欧拉函数)
原题链接:传送门题意:给你一个函数 F(),F(n) 就是 1-n 之内两个数 gcd(a,b) = 1 的总个数。思路:很显然,是求欧拉函数的。F(n) = F(n-1) + phi[i],直接套欧拉函数模板。// #include &amp;amp;amp;amp;lt;bits/stdc++.h&amp;amp;amp;amp;gt;#include &amp;amp;amp;amp;lt;iostream&amp;amp;amp原创 2018-11-27 21:00:40 · 173 阅读 · 0 评论 -
POJ - 2409 Let it Bead (Polya计数)
原题链接:传送门/* Polya定理c种颜色染 n个对象方案数 L = 1/n * (∑(c^g)) g是置换gi的循环节数置换分为旋转和翻转两种方式旋转i格时,循环节为 gcd(n,i)翻转时要考虑n的奇偶,n为奇数时:循环节为(n+1)/2 * 循环群 n 个n为偶数时(举正方形):循环群有两类,按边中点 循环节为 n/2 * 循环群 n/2按对角线 循环节数为 ...原创 2018-12-09 20:30:01 · 186 阅读 · 0 评论 -
中国剩余定理
求解一元线性同余方程组:这里要求mi两两互质。令 M = m1 * m2 * m3 *···* mk,中国剩余定理说明:假设整数m1,m2, … ,mn两两互质,则对任意的整数:a1,a2, … ,an,方程组 (S) 有解,并且通解可以用如下方式构造得到:设 M = m1 * m2 * ···* mn 是整数m1,m2, … ,mn的乘积,并设 Mi = M/mi, 是除了mi以外的n...原创 2018-12-25 15:16:58 · 160 阅读 · 0 评论 -
两种方法求欧拉函数
直接求法:#include <bits/stdc++.h>using namespace std;typedef long long ll;ll Eular(ll n){ ll res = n; for(int i=2;i*i<=n;i++){ if(n%i == 0) res = res/i*(i-1); //先除后乘防止中间数据溢出...原创 2019-01-23 17:23:50 · 463 阅读 · 0 评论 -
D-小a与黄金街道(欧拉函数 +快速幂)
原题链接:传送门题意:给四个数 n,k,A,B。小a会从1走到n-1,小b从n-1走到1。小a当前位置记为x,小b当前位置记为y。当gcd(x,n)==1时,小a的黄金A会变为A * kx,gcd(y,n) == 1 时,小b的黄金B会变为B * ky。问小a走到n-1时,他们手中的黄金数为多少。思路:主要就是求1到n-1中与n互质的数之和——可以用欧拉来求,公式phi[n]*n/2可以直接求...原创 2019-01-23 17:44:17 · 201 阅读 · 0 评论 -
欧拉降幂
降幂公式:ABmodC = ABmodφ[C]+φ[C]modC(降幂公式中 phi[] 为欧拉函数)// https://ac.nowcoder.com/acm/contest/330/E#include &lt;bits/stdc++.h&gt;using namespace std;const int Mod = 1e9+7;typedef long long ll;char...原创 2019-03-02 23:04:44 · 327 阅读 · 0 评论 -
不凡的夫夫 斯塔林公式求阶乘位数
https://ac.nowcoder.com/acm/contest/75/A题意:求解 n! 在八进制下的位数。一个整数n的位数的计算方法为:log10(n)+1n=10m故n的位数为 m = log10(n!)+1如12345 = 1.2345*104,那么(int)log10(12345) = 4,再加上1就是这个数的位数。那么对于 n! 的八进制数的位数长度,log8n! ...原创 2019-03-02 23:01:36 · 278 阅读 · 0 评论 -
51Nod 1057 n的阶乘
http://www.51nod.com/Challenge/Problem.html#!#problemId=1057正常的可以直接通过模拟来求阶乘,用一个数组保存阶乘的每一位。但是当n太大的时候,就不行了。所以这里用每8位进位的方法,就是数组中的每一个数都保存8位数,超过八位数才进位。#include &lt;iostream&gt;#include &lt;cstdio&gt;#...原创 2019-03-03 17:47:32 · 195 阅读 · 0 评论 -
华华教月月做数学(快速幂+快速乘)
https://ac.nowcoder.com/acm/contest/392/B?tdsourcetag=s_pctim_aiomsg#include <bits/stdc++.h>using namespace std;typedef long long ll;ll a,b,Mod; ll Mult(ll a,ll b,ll Mod){ //快速乘 ll re...原创 2019-03-12 20:20:43 · 197 阅读 · 0 评论 -
几种常用求素数方法
6n+1法 判断素数#include &amp;lt;bits/stdc++.h&amp;gt;using namespace std;bool isprime(int n){ //判断素数 double n_sqrt = double(sqrt(n)); if(n == 1) return false; if(n==2 || n==3) ...原创 2018-11-14 21:41:31 · 2086 阅读 · 0 评论 -
LightOJ - 1220 Mysterious Bacteria(唯一分解定理+思维)
原题链接:传送门题意:输入 t 组数n,每个数n = bp,求 p 的最大值。思路:一开始以为是求 n = b1p1 * b2p2 * b3p3 * … *bnpn 中的最大的p,后来才注意到是 n = bp 中 p 的最大值…可以先用唯一分解定理求出b1,b2,b3…bn,然后求出b1到bn的gcd,就是n = bp了。如12 = 22 * 3,那么12 = 121,gcd(2,1) =...原创 2018-11-19 18:23:15 · 175 阅读 · 0 评论 -
HDU--1576 A/B 拓展欧几里得求逆元
原题链接:传送门Description要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973) = 1)。Input数据的第一行是一个T,表示有T组数据。每组数据有两个数n(0 &amp;lt;= n &amp;lt; 9973)和B(1 &amp;lt;= B &amp;lt;= 10^9)。Output对应每组数据输出(A/B)%9973...原创 2018-10-26 10:03:33 · 177 阅读 · 0 评论 -
LightOj 1282 Leading and Trailing(快速幂取模 + 对数)
原题链接:传送门DescriptionYou 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 with an integer T (≤ 10...原创 2018-11-06 18:17:23 · 157 阅读 · 0 评论 -
Miller–Rabin(米勒拉宾求大素数)
首先需要知道两个定理:1: 费马小定理: 假如p是素数,且gcd(a,p)=1,那么 a(p-1)≡1(mod p)。2:二次探测定理:如果p是素数,x是小于p的正整数,且,那么要么x=1,要么x=p-1。 证明:这是显然的,因为相当于p能整除,也即p能整除(x+1)(x-1)。 由于p是素数,那么只可能是x-1能被p整除(此时x=1) 或 x+1能被p整除(此时x=p-1)。...原创 2018-07-13 15:22:28 · 740 阅读 · 0 评论 -
矩阵快速幂
51nod 1242 斐波那契数列的第N项 NYOJ - 148 fibonacci数列(二) NYOJ - 301 递推求值矩阵相乘满足结合律(A*B)*C = A*(B*C) (矩阵相乘模板)让原矩阵R乘加速矩阵base的n次方 由此可以与数的快速幂结合 就是矩阵快速幂。 矩阵快速幂的关键是构造。 只要能够构造出原矩阵和基数矩阵,题就解了。 构造时根据递推公...原创 2018-05-03 16:44:18 · 202 阅读 · 0 评论 -
PAT L1-48.矩阵相乘
原题链接传送门#include &lt;bits/stdc++.h&gt;using namespace std;struct node { int coo[100][100];} A,B,C; //定义结构体存储矩阵A,B,C的各元素 int main() { int Ra,Ca,Rb,Cb; //表示矩阵A、矩阵B的行...原创 2018-05-03 09:39:08 · 213 阅读 · 0 评论 -
LightOJ - 1259 Goldbach`s Conjecture(素数)
原题链接:传送门DescriptionGoldbach’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 expressed as the su...原创 2018-11-08 11:04:20 · 155 阅读 · 0 评论 -
Educational Codeforces Round 54 (Rated for Div. 2) B.Divisor Subtraction (素数 + 思维)
原题链接:传送门Descriptionoutputstandard outputYou are given an integer number n. The following algorithm is applied to it:1.if n=0, then end algorithm;2.find the smallest prime divisor d of n;3.subtr...原创 2018-11-14 19:47:16 · 202 阅读 · 0 评论 -
Educational Codeforces Round 54 (Rated for Div. 2) C - Meme Problem(数学)
原题链接:传送门题意:给你一个数d,问是否存在 a 和 b,使得a + b = d 并且a * b = d,没有输出N,有则输出Y并输出a 和 b 的值.思路:联立两个方程组,得到一个一元二次方程 a2 - ad + d = 0,即 x2 - ax + a = 0.即可求出 a ,b.#include &lt;bits/stdc++.h&gt;typedef long long ll;u...原创 2018-11-14 20:28:12 · 204 阅读 · 0 评论 -
LightOJ - 1214 Large Division(高精度取模)
原题链接:传送门题意:给你两个数a和b,问你a是否能整除b。(-10200 ≤ a ≤ 10200),b是32位有符号整型。思路:用一个数1234举例,可以写成 ( ( ( ( (1 * 10) + 2) * 10) + 3 ) * 10 ) + 4,而根据(m+n)%Mod = (m%Mod) + (n%Mod) ) % Mod,可以求出b是否可被a整除#include &lt;bit...原创 2018-11-15 10:41:52 · 286 阅读 · 0 评论 -
快速乘&&快速幂
快速幂ll kpow(ll a,ll b){ ll res = 1,base = ans; while(b){ if(b&1) res = res * base % Mod; base = base * base % Mod; b >>= 1; } return res;}快速乘时...原创 2019-04-04 11:37:24 · 156 阅读 · 0 评论