
数论
文章平均质量分 90
xuanweiace
一个热爱算法竞赛的弱校ACMer路过。青大本,浙大硕,方向后端开发,菜鸡一枚,奋斗ing...
展开
-
【HDU - 5943】Kingdom of Obsession(数论,素数间隔结论,构造,思维,匈牙利算法,匹配问题)
题干:There is a kindom of obsession, so people in this kingdom do things very strictly.They name themselves in integer, and there arennpeople with their id continuous(s+1,s+2,⋯,s+n)(s+1,s+2,⋯,s+n...原创 2019-03-10 16:27:14 · 325 阅读 · 0 评论 -
【牛客 - 280C】约数(数论,GCD,数学,分解因子)
题干: Actci上课睡了一觉,下课屁颠屁颠的去找数学老师补课,问了老师一个题目: 给出两个数a,b,问a和b的全部公约数是什么?数学老师一看这道题太简单了,不屑回答,于是就交给了你。输入描述:一行两个数a,b.输出描述:a和b的全部公约数,每个数字之间空格隔开。示例1输入复制25 37输出复制1示例2输入复制25...原创 2018-12-29 21:22:55 · 389 阅读 · 0 评论 -
【CodeForces - 347C 】Alice and Bob (思维,数学,等差数列)
题干:It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of n distinct integers. And then they take turn...原创 2018-12-06 09:44:14 · 956 阅读 · 0 评论 -
【牛客 - 303B第十五届浙江大学宁波理工学院程序设计大赛(同步赛)】Fibonacci and Counting(Fib数性质,gcd辗转相除法性质)
题干: 我们这样定义斐波那契数列,F[1]=1,F[2]=1,当n>2时F[n]=F[n-1]+F[n-2]。斐波那契数列的前10项为:1,1,2,3,5,8,13,21,34,55。欧几里得算法求解两个数的最大公约数。我们记gcd(a,b)为整数a与b的最大公约数。当b=0时,gcd(a,0)=a,否则gcd(a,b)=gcd(b,a%b)。其中%为取余运算。在算法设...原创 2018-12-09 10:40:46 · 264 阅读 · 0 评论 -
【CodeForces - 27E】Number With The Given Amount Of Divisors (数论,数学,反素数)
题干:Given the numbern, find the smallest positive integer which has exactlyndivisors. It is guaranteed that for the givennthe answer will not exceed1018.InputThe first line of the input con...原创 2018-12-08 12:44:53 · 367 阅读 · 0 评论 -
【CodeForces - 151C】Win or Freeze (博弈,数学,唯一素数分解)
题干:You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer q. During a move a player shou...原创 2018-11-21 18:54:38 · 525 阅读 · 0 评论 -
【POJ - 2909 】Goldbach's Conjecture (哥德巴赫猜想,数论,知识点结论)
题干:For any even number n greater than or equal to 4, there exists at least one pair of prime numbers p1 and p2 such thatn = p1 + p2This conjecture has not been proved nor refused yet. No one is ...原创 2018-11-12 21:07:08 · 569 阅读 · 0 评论 -
【POJ - 2262】Goldbach's Conjecture (数论,哥德巴赫猜想,知识点结论)
题干:In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in which he made the following conjecture: Every even number greater than 4 can be written as the s...原创 2018-11-12 20:59:38 · 418 阅读 · 0 评论 -
【 HDU - 5363】Key Set(水题,快速幂,组合数学)
题干:soda has a set SS with nn integers {1,2,…,n}{1,2,…,n}. A set is called key set if the sum of integers in the set is an even number. He wants to know how many nonempty subsets of SS are key set....原创 2018-11-12 20:46:26 · 334 阅读 · 0 评论 -
【POJ - 3048】Max Factor (数论,打表,水题)
题干:To improve the organization of his farm, Farmer John labels each of his N (1 <= N <= 5,000) cows with a distinct serial number in the range 1..20,000. Unfortunately, he is unaware that the ...原创 2018-11-12 20:25:57 · 650 阅读 · 0 评论 -
【HDU - 2012】素数判定(水题,数论,打表)
题干: 解题报告: AC代码1:#include<bits/stdc++.h>#define MAX 10000//求MAX范围内的素数 using namespace std; long long su[MAX],cnt; bool isprime[MAX]; void prime() { cnt=1; memse...原创 2018-11-12 20:13:39 · 248 阅读 · 0 评论 -
【CodeForces - 472A】Design Tutorial: Learn from Math (tricks,思维,数论,打表)
题干:One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.For example, there is a s...原创 2019-01-22 00:33:16 · 272 阅读 · 0 评论 -
【牛客 - 331G】炫酷数字(反素数打表 或 扩展埃式筛法,结论)
题干:小希希望你构造一个最小的正整数,使得其有n个因子。输入描述:第一行一个整数T表示数据组数每组数据第一行输入一个正整数n,表示其因子数。n≤1,000,000n≤1,000,000T≤1,000,000T≤1,000,000输出描述:输出一行一个整数,表示你构造出的这个数。注意:你需要保证你构造的数≤1,000,000≤1,000,000,如果在这个范围里...原创 2019-02-01 11:55:09 · 657 阅读 · 0 评论 -
【牛客 - 327牛客寒假算法基础集训营2 I】处女座的测验(二)(积性函数性质,数论,素数唯一性分解,STL)
题干:链接:https://ac.nowcoder.com/acm/contest/327/I来源:牛客网 现在处女座顺利的完成了测验,处女座想要知道知道自己输出的结果是否正确。他希望知道自己有自己输出的数中有多少对是不满足要求的。 更具体的,处女座想知道下面程序段的答案int main(){ int n; cin>>...原创 2019-02-24 22:05:00 · 273 阅读 · 0 评论 -
【牛客 - 181F】子序列(容斥,组合数,费马小定理)
题干:题目描述给出一个长度为n的序列,你需要计算出所有长度为k的子序列中,除最大最小数之外所有数的乘积相乘的结果 输入描述:第一行一个整数T,表示数据组数。对于每组数据,第一行两个整数N,k,含义如题所示接下来一行N个整数,表示给出的序列保证序列内的数互不相同输出描述:对于每组数据,输出一个整数表示答案,对取模每组数据之间以换行分割 示例...原创 2019-02-19 11:51:35 · 301 阅读 · 0 评论 -
【蓝桥杯官网试题 -算法训练】素因子去重(数学,数论,因子约数)
题干:问题描述 给定一个正整数n,求一个正整数p,满足p仅包含n的所有素因子,且每个素因子的次数不大于1输入格式 一个整数,表示n输出格式 输出一行,包含一个整数p。样例输入1000样例输出10数据规模和约定 n<=10^12 样例解释:n=1000=2^3*5*3,p=2*5=10 解题报告: 就是个整数的唯一性分...原创 2019-02-17 21:12:07 · 827 阅读 · 0 评论 -
【牛客 - 练习】约数个数的和(数论,数学)
题干: 给个n,求1到n的所有数的约数个数的和~输入描述:第一行一个正整数n输出描述:输出一个整数,表示答案示例1输入复制3输出复制5说明样例解释:1有1个约数12有2个约数1,23有2个约数1,3备注:n <= 100000000解题报告: 看到数据范围,nlogn打表肯定是不行的,但是因为求的...原创 2019-02-16 12:06:24 · 826 阅读 · 0 评论 -
【牛客 -330E 】Applese 涂颜色(费马小定理,超级快速幂)
题干: 精通程序设计的 Applese 叕写了一个游戏。在这个游戏中,有一个 n 行 m 列的方阵。现在它要为这个方阵涂上黑白两种颜色。规定左右相邻两格的颜色不能相同。请你帮它统计一下有多少种涂色的方法。由于答案很大,你需要将答案对 109+7109+7 取模。输入描述:仅一行两个正整数 n, m,表示方阵的大小。输出描述:输出一个正整数,表示方案数对 109+71...原创 2019-01-29 23:47:32 · 285 阅读 · 0 评论 -
【计蒜客 - 蓝桥训练】欧拉函数(数学,数论,模板)
题干:在数论中,对正整数 nn,欧拉函数 \varphi (n)φ(n) 是小于等于 nn 的正整数中与 nn 互质的数的数目。例如 \varphi (12)=4φ(12)=4,因为 1,5,7,111,5,7,11 均和 1212 互质。代码框中的代码是一种求欧拉函数的实现,请分析并填写缺失的代码,计算出 \varphi(n)φ(n) 的值。提示:若 n=p_{1}^}p_{2}...原创 2019-02-15 12:11:34 · 489 阅读 · 0 评论 -
【LeetCode - 279】完全平方数(四平方和定理,数论,图论,dp)
题干:给定正整数 n,找到若干个完全平方数(比如 1, 4, 9, 16, ...)使得它们的和等于 n。你需要让组成和的完全平方数的个数最少。示例 1:输入: n = 12输出: 3 解释: 12 = 4 + 4 + 4.示例 2:输入: n = 13输出: 2解释: 13 = 4 + 9.解题报告:很多人第一眼看到这个问题,想到的第一种做法就是使用贪心算...原创 2019-02-02 21:17:13 · 1580 阅读 · 0 评论 -
【牛客 - 317D】小a与黄金街道(数论,tricks)
题干:链接:https://ac.nowcoder.com/acm/contest/317/D来源:牛客网 小a和小b来到了一条布满了黄金的街道上。它们想要带几块黄金回去,然而这里的城管担心他们拿走的太多,于是要求小a和小b通过做一个游戏来决定最后得到的黄金的数量。游戏规则是这样的:假设道路长度为nn米(左端点为00,右端点为nn),同时给出一个数kk(下面会提到kk的用法)设小...原创 2019-01-28 00:58:15 · 199 阅读 · 0 评论 -
【牛客 - 331J】炫酷数学(打表猜结论,按位枚举证明)
题干:小希最近想知道一个东西,就是A+B=A|B(其中|为按位或)的二元组有多少个。当然,直接做这个式子对小希来说太难了,所以小希改变了一些条件,她仅想知道其中A,B<NA,B<N的情况,其中N为2的幂次。当然,(A=1,B=0)和(A=0,B=1)被认为是不同的二元组。输入描述:第一行输入一个非负整数M。N=2M,M≤100N=2M,M≤100 即2...原创 2019-02-01 12:03:07 · 501 阅读 · 0 评论 -
【51Nod - 1106 】质数检测 (水题,数论)
题干:给出N个正整数,检测每个数是否为质数。如果是,输出"Yes",否则输出"No"。Input第1行:一个数N,表示正整数的数量。(1 <= N <= 1000) 第2 - N + 1行:每行1个数(2 <= Sii <= 10^9)Output输出共N行,每行为 Yes 或 No。Sample Input523456Sam...原创 2018-11-12 19:22:21 · 272 阅读 · 0 评论 -
【FZU - 1759】Super A^B mod C (数论,快速幂,快速乘,欧拉降幂,指数循环节,模板)
题干:Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=1000000000,1<=B<=10^1000000).InputThere are multiply testcases. Each testcase, there is one line contai...原创 2018-10-29 00:00:59 · 244 阅读 · 0 评论 -
【牛客 - 185A】无序组数 (思维,数学,因子个数)
题干:时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 131072K,其他语言262144K64bit IO Format: %lld题目描述给出一个二元组(A,B)求出无序二元组(a,b) 使得(a|A,b|B)的组数无序意思就是(a,b)和(b,a) 算一组.输入描述:第一行数据组数 T(1≤T≤10000)接下来T行,每行两个正整数 A,B(1≤...原创 2018-09-13 11:41:37 · 251 阅读 · 0 评论 -
【CodeForces - 764D】Timofey and rectangles (四色定理 + 找规律 + 构造)
题干:One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have...原创 2018-09-12 16:34:32 · 342 阅读 · 0 评论 -
【HDU -1568】 Fibonacci(斐波那契通项公式+取对数)
FibonacciProblem Description2007年到来了。经过2006年一年的修炼,数学神童zouyu终于把0到100000000的Fibonacci数列(f[0]=0,f[1]=1;f[i] = f[i-1]+f[i-2](i>=2))的值全部给背了下来。接下来,CodeStar决定要考考他,于是每问他一个数字,他就要把答案说出来,不过有的数字太长了。所以规定超...转载 2018-09-11 11:46:55 · 687 阅读 · 0 评论 -
【CodeForces - 833A】The Meaningless Game(思维题,数学,可用牛顿迭代法,知识点总结)
题干:Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.The game consists of multiple rounds. Its rules are very simple: in each round, a natural num...原创 2018-09-04 16:05:11 · 561 阅读 · 0 评论 -
ACM竞赛、数论内容常用的定理(求解(a/b)%c,乘法逆元,费马小定理)
如果b与c互素,则(a/b)%c=a*b^((c)-1)%c其中是欧拉函数。或者(a/b)%c=a*b^(c-2)%c如果b与c不互素,则(a/b)%c=(a%bc)/b对于b与c互素和不互素都有(a/b)%c=(a%bc)/b成立乘法逆元用扩展欧几里得定理:例题:ZOJ - 3609题干:The modular modular multiplicative inverse...原创 2018-07-27 20:45:55 · 1812 阅读 · 0 评论 -
无数种求逆元的方法总结
乘法逆元对于缩系中的元素,每个数a均有唯一的与之对应的乘法逆元x,使得ax≡1(mod n)一个数有逆元的充分必要条件是gcd(a,n)=1,此时逆元唯一存在逆元的含义:模n意义下,1个数a如果有逆元x,那么除以a相当于乘以x。下面给出求逆元的几种方法:1.扩展欧几里得给定模数m,求a的逆相当于求解ax=1(mod m)这个方程可以转化为ax-my=1然后套用求二...原创 2018-07-29 13:57:38 · 15077 阅读 · 0 评论 -
【HDU - 2104】hide handkerchief (素数)
题干: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...原创 2018-07-25 00:23:11 · 287 阅读 · 0 评论 -
【HDU - 1852】 Beijing 2008()
题干:Beijing 2008Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/65535 K (Java/Others)Total Submission(s): 917 Accepted Submission(s): 394 Problem DescriptionAs we all know, t...原创 2018-07-25 00:01:23 · 261 阅读 · 0 评论 -
【HDU - 1452】 Happy 2004(因子和,逆元,快速幂)
题干: Happy 2004Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1863 Accepted Submission(s): 1361 ...原创 2018-07-24 23:57:47 · 338 阅读 · 0 评论 -
【HDU - 6441】Find Integer (费马大定理 + 奇偶数列法构造勾股定理)
题干:people in USSS love math very much, and there is a famous math problem . give you two integers nn,aa,you are required to find 22 integers bb,cc such that anan+bn=cnbn=cn.Inputone line contai...原创 2018-09-10 14:59:33 · 435 阅读 · 0 评论 -
【CodeForces - 574C】Bear and Poker(思维,剪枝,数学)
题干:Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-t...原创 2018-09-19 19:50:47 · 297 阅读 · 0 评论 -
【CodeForces - 357D】Xenia and Hamming (字符串问题,数论,思维)
题干:Xenia is an amateur programmer. Today on the IT lesson she learned about the Hamming distance.The Hamming distance between two strings s = s1s2... sn and t = t1t2... tn of equal length n is val...原创 2018-10-10 20:11:13 · 328 阅读 · 0 评论 -
【HDU - 5585】Numbers (水题,数学,数论)
题干:There is a number N.You should output "YES" if N is a multiple of 2, 3 or 5,otherwise output "NO".InputThere are multiple test cases, no more than 1000 cases. For each case,the line contains...原创 2018-10-19 01:10:50 · 251 阅读 · 0 评论 -
【CodeForces - 1051B】Relatively Prime Pairs (构造,思维,素数,水题)
题干:You are given a set of all integers from ll to rr inclusive, l<rl<r, (r−l+1)≤3⋅105(r−l+1)≤3⋅105and (r−l)(r−l) is always odd.You want to split these numbers into exactly r−l+12r−l+12 pairs...原创 2018-09-29 00:57:14 · 386 阅读 · 0 评论 -
【CodeForces - 1047B 】Cover Points (数学,构造,思维)
题干:There are nn points on the plane, (x1,y1),(x2,y2),…,(xn,yn)(x1,y1),(x2,y2),…,(xn,yn).You need to place an isosceles triangle with two sides on the coordinate axis to cover all points (a point i...原创 2018-09-29 00:48:36 · 379 阅读 · 0 评论 -
【CodeForces - 1027C】Minimum Value Rectangle (数学,公式化简,思维,卡常卡memset)
题干:You have nn sticks of the given lengths.Your task is to choose exactly four of them in such a way that they can form a rectangle. No sticks can be cut to pieces, each side of the rectangle must...原创 2018-10-18 00:34:00 · 382 阅读 · 0 评论