
数论
文章平均质量分 95
ACM数论问题
DrGilbert
慵懒的凡人
展开
-
佩尔方程及其在一类二元二次丢番图方程的推广
文章目录一般佩尔方程性质求最小解暴力写法连分数写法推广佩尔方程一般佩尔方程形如x2−Dy2=1(D>0)x^2-Dy^2=1(D>0)x2−Dy2=1(D>0)的方程,即为佩尔方程。性质1.容易得到,{x=±1y=0\begin{cases}x=\pm1\\y=0\end{cases}{x=±1y=0必是该方程的解。若DDD为平方数,则只有这种解,反之则有无数多组解。证明略,见百度百科。2.若一组解(x1,y1)(x_1,y_1)(x1,y1)是非(±1,0)(\pm1原创 2021-04-19 21:35:20 · 1066 阅读 · 1 评论 -
P4157 [SCOI2006]整数划分 (数学推导+大数)
原题题面读入一个正整数nnn(10≤n≤3100010≤n≤3100010≤n≤31000)。要求将nnn写成若干个正整数之和,并且使这些正整数的乘积最大。例如,n=13n=13n=13,则当n表示为4+3+3+34+3+3+34+3+3+3(或2+2+3+3+32+2+3+3+32+2+3+3+3)时,乘积=108108108为最大。输入格式只有一个正整nnn(10≤n≤3100010≤n≤3100010≤n≤31000)输出格式第1行输出一个整数,为最大乘积的位数。第2行输出最大乘积的前1原创 2020-10-04 16:23:06 · 338 阅读 · 1 评论 -
Groundhog Chasing Death 2020牛客多校第九场(质因子分解+欧拉降幂)
原题题面As we all know,“Groundhog chasing death” means “GCD”,while “GCD” stands for “greatest common divisor”.So you need to calculate ∏i=ab∏j=cdgcd(xi,yj)\prod_{i=a}^b\prod_{j=c}^d\gcd(x^i,y^j)∏i=ab∏j=cdgcd(xi,yj) modulo 998244353998244353998244353输入格式原创 2020-08-09 15:22:18 · 292 阅读 · 0 评论 -
HDU 6833 A Very Easy Math Problem(莫比乌斯反演)
原题题面Given you n,x,k , find the value of the following formula:∑a1=1n∑a2=1n...∑ax=1n(∏j=1xajk)f(gcd(a1,a2,...ax))∗gcd(a1,a2,...ax)\sum_{a_1=1}^{n}\sum_{a_2=1}^{n}...\sum_{a_x=1}^{n}(\prod_{j=1}^{x}a_{j}^{k})f(gcd(a_1,a_2,...a_x))*gcd(a_1,a_2,...a_x)∑a1=1原创 2020-08-07 17:17:30 · 328 阅读 · 0 评论 -
HDU 6588 Function 2019杭电多校第一场(莫比乌斯反演)
原题题面Jerry is fond of functions. He thinks the mystery of the universe is hidden behind the notations, variables and numbers.Of all functions, he thinks gcd and ⌊x⌋⌊x⌋⌊x⌋ are the most fascinating, and that something combines gcd with truncation should be原创 2020-08-07 15:13:46 · 311 阅读 · 0 评论 -
HDU 6825 Set1 2020杭电多校(数学推导)
原题题面You are given a set S=1..nS={1..n}S=1..n. It guarantees that nnn is odd. You have to do the following operations until there is only 111 element in the set:Firstly, delete the smallest element of SSS. Then randomly delete another element from SSS.Fo原创 2020-08-04 22:24:49 · 300 阅读 · 0 评论 -
HDU 6822 Paperfolding 2020杭电多校第五场(数学推导)
原题题面There is a piece of paper in rectangular shape with sufficient length and width (lay flat on the table). Execute an operation instruction according to a string of length n from left to right that only contains 4 different characters of L,R,U,DL,R,U,DL原创 2020-08-04 20:13:28 · 417 阅读 · 0 评论 -
HDU 6814 Tetrahedron 2020杭电多校第五场 (数学推导)
原题题面Generate three integers a, b, and c in [1,n][1,n][1,n] with equal probability independently, and use them as the three right-angle side length of a right-angled tetrahedron. Find the expectation of the reciprocal square of the distance from the right-原创 2020-08-04 19:23:26 · 544 阅读 · 0 评论 -
HDU 6755 Fibonacci Sum (二项式定理+预处理) 2020杭电多校第一场
原题题面The Fibonacci numbers are defined as below:F0=0,F1=1F_0=0,F_1=1F0=0,F1=1Fn=Fn−2+Fn−1(n>1)F_n=F_{n-2}+F_{n-1}(n>1)Fn=Fn−2+Fn−1(n>1)Given three integers NNN, CCC and KKK, calculate the following summation:(F0)K+(FC)K+(F2C)K+(F3C)K...+(原创 2020-07-22 13:29:46 · 1569 阅读 · 3 评论 -
Harder Gcd Problem 2020牛客多校第四场(质数筛+构造)
原题题面给出一正整数nnn,找到{1,2,3,...,n}\{1,2,3,...,n\}{1,2,3,...,n}的两个子集合A,BA,BA,B,使:(1)∣A∣=∣B∣=m,A∩B=∅|A|=|B|=m,A∩B=∅∣A∣=∣B∣=m,A∩B=∅(2)令A={a1,a2...am},B={b1,b2,...bm}A=\{a_1,a_2...a_m\},B=\{b_1,b_2,...b_m\}A={a1,a2...am},B={b1,b2,...bm},存在两种排列方式{p1,p2,...p原创 2020-07-20 22:23:00 · 308 阅读 · 0 评论 -
Fraction Construction Problem 2020牛客多校第三场(扩展欧几里得)
原题题面有T个输入。每组输入给出两个正整数a,b(a,b≤2×106)a,b(a,b\leq 2 × 10^6)a,b(a,b≤2×106)。请找到四个正整数c,d,e,f(f<b,d<b,1≤c,e≤4×1012)c,d,e,f(f<b,d<b,1\leq c,e \leq 4× 10^{12})c,d,e,f(f<b,d<b,1≤c,e≤4×1012),使他们满足:cd−ef=ab\frac{c}{d}-\frac{e}{f}=\frac{a}{b}dc−f原创 2020-07-18 19:54:58 · 1212 阅读 · 1 评论 -
Easy Integration(Wallis积分)(2020牛客多校第一场J题)
原题题面时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 262144K,其他语言524288KGiven n, find the value of ∫01(x−x2)n dx\int_0^1 {(x-x^2)^n} \,{\rm d}x∫01(x−x2)ndx.It can be proved that the value is a rational number pq\frac{p}{q}qp.Print the result as p⋅q−1 mod 9原创 2020-07-12 19:04:44 · 1527 阅读 · 0 评论 -
洛谷 P6583 回首过去 (数论+容斥定理)
写在前面笔者是一名十八线蒟蒻ACMer,文中可能会有多处错误与疏漏,欢迎指出。原题题面洛谷 P6583 回首过去给定正整数 nnn,求出有序整数对 (x,y)(x,y)(x,y) 的个数,满足:1≤x,y≤n,1≤x,y≤n1\leq x,y\leq n,1≤x,y≤n1≤x,y≤n,1≤x,y≤n 且xy\frac{x}{y}yx 可以表示为十进制有限小数。对于40%的数据,1≤n≤1031\leq n\leq 10^31≤n≤103,对于40%的数据,1≤n≤1071\leq n\leq原创 2020-06-02 18:58:23 · 506 阅读 · 0 评论 -
Codeforces Round #641 (Div. 2) C. Orac and LCM(质因子分解)
写在前面笔者是一名十八线蒟蒻ACMer,文中可能会有多处错误与疏漏,欢迎指出。原题体面原题地址时间:3 seconds空间:256MFor the multiset of positive integers s=s1,s2,…,sks={s_1,s_2,…,s_k}s=s1,s2,…,sk, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow:gcd(s)gcd(s原创 2020-05-13 22:43:29 · 266 阅读 · 0 评论 -
ACM数列相关
写在前面按理来说,求数列通项本应该属于数学范围,但ACM中也有数列推导题的出现,处于方便,笔者决定把一些常见数列整理出来。注:笔者是一名十八线蒟蒻,如果有错误请在评论区下留言,谢谢您帮助我做得更好。前置知识无!带上你的小脑瓜跟着学就是了!一、基础数列(等比、等差、等比*等差,累加,累乘)众所周知,(1)对于an=an−1+d(n≥2)a_n=a_{n-1}+d(n\geq2)an=...原创 2020-02-05 23:21:35 · 502 阅读 · 0 评论 -
HDU 6632 discrete logarithm problem (Pohlig-hellman算法)
原题题面给定三个数 p,a,b(p∈prime,65537≤p≤1018,2≤a,b≤p−1)p,a,b(p∈prime,65537≤p≤10^{18}, 2≤a,b≤p−1)p,a,b(p∈prime,65537≤p≤1018,2≤a,b≤p−1), p−1p−1p−1 的质因子只有 222 和/或 333. 请算出最小的 xxx 使得ax≡b(mod p)a^x\equiv b(...原创 2020-01-23 20:43:26 · 494 阅读 · 0 评论 -
离散对数问题——pohlig-hellman算法讲解(有例子)
写在前面一切都要从去年8月的多校开始说起。笔者在多校某场比赛中,遇到一个离散对数的题:HDU 6632给定a,b,p(p∈prime,65537≤p≤1e18,2≤a,b≤p−1且p−1的质因子只能由2(和/或)3组成)a,b,p(p∈prime,65537\leq p \leq 1e18,2\leq a,b\leq p-1且p-1的质因子只能由2(和/或)3组成)a,b,p(p∈prime...原创 2020-01-22 13:22:45 · 18648 阅读 · 20 评论 -
HDU 6467 简单数学题 广东工业大学第十四届程序设计竞赛 (数学推导+快速幂)
原题题面已知求F(n)F(n)F(n) modmodmod 1e9+71e9+71e9+7题面分析乍一看,是个很难的题。仔细一看,其实是个水题(手动滑稽保命)。众所周知我们可以发现ΣΣΣ是通过构造F(n−1)F(n-1)F(n−1)来消去的。于是↓↓↓两式相减得↓↓↓看到这里有些聪明的读者就可能看出来了。这是一个经典结论, 下面给出证明。我们都知道因此我们构造一个...原创 2019-08-21 11:06:34 · 284 阅读 · 0 评论 -
牛客练习赛53 B 美味果冻(数学推导+快速幂优化)
写在前面需要学会的前置技能:快速幂逆元一定的数学推导能力原题题面求∑i=1n∑j=1ii⌊\sum_{i=1}^{n}\sum_{j=1}^{i}i\lfloor∑i=1n∑j=1ii⌊ij\frac{i}{j}ji⌋j mod (1e9+7)\rfloor^{j}\ mod\ (1e9+7)⌋j mod (1e9+7)的结果。(n≤3e6...原创 2019-10-12 09:18:56 · 477 阅读 · 0 评论 -
Codeforces Round #589 (Div. 2) C.Primes and Multiplication (数学推导+容斥原理+快速幂)
写在前面需要学会的前置技能:快速幂一颗热爱学习的心原题体面时间限制t:1 second空间限制:256 MBLet’s introduce some definitions that will be needed later.Let prime(x)prime(x)prime(x) be the set of prime divisors of xxx. For example, ...原创 2019-09-30 11:07:24 · 368 阅读 · 0 评论 -
2019 南昌ICPC网络赛 H题 The Nth Item (二阶线性数列递推+快速幂优化) or (矩阵快速幂+广义斐波那契循环节)
原题题面For a series FFF:F(0)=0,F(1)=1F(0) = 0,F(1) = 1F(0)=0,F(1)=1F(n)=3∗F(n−1)+2∗F(n−2),(n≥2)F(n) = 3*F(n-1)+2*F(n-2),(n \geq 2)F(n)=3∗F(n−1)+2∗F(n−2),(n≥2)We have some queries. For each query NNN,...原创 2019-09-08 23:58:27 · 893 阅读 · 3 评论 -
HDU 6680 Rikka with Quicksort(2019杭电多校第9场1001) 数学推导+分块
HDU 6680 Rikka with Quicksort(2019杭电多校第9场1001) 数学推导+分块原题题面题面分析分块这是笔者的第一篇博客。为了能让更多的人看懂。所以本文的叙述的节奏相对很缓慢,有基础的同学可以选择性地跳读。作为一个十八线的蒟蒻ACMer,文中可能出现各种BUG和表达歧义的情况,同时,笔者对Markdown的编辑器使用并不是特别熟练,望各位能给我提出意见,帮助我做得更...原创 2019-08-21 08:56:01 · 1354 阅读 · 7 评论 -
2019 南京ICPC网络赛 B super_log(幂塔函数求模、扩展欧拉降幂)
注:笔者是一名十八线蒟蒻 ACMerACMerACMer,因此文中可能有许多 BUGBUGBUG ,请大佬们在评论区下留言,我会尽快改进。原题In Complexity theory, some functions are nearly O(1)O(1)O(1), but it is greater then O(1)O(1)O(1). For example, the complexity ...原创 2019-09-02 15:16:33 · 798 阅读 · 7 评论