摘要:题目: Bamboo Pole-vault is a massively popular sport in Xzhiland. And Master Phi-shoe is a very popular coach for his success. He needs some bamboos for
阅读全文
摘要:Webster defines prime as:prime (prim) n. [ME, fr. MF, fem. of prin first, L primus; akin to L prior] 1: first intime: original 2 a: having no factor
阅读全文
摘要:Time limit3000 msOSLinux Write a program, that computes the number of different prime factors in a positive integer.InputThe input tests will consist
阅读全文
摘要:青蛙的约会 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 139755 Accepted: 31803 Description 两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面。它们很高兴地发现它们住在同一条纬度线上
阅读全文
摘要:求解a*x = b (mod p) #include<bits/stdc++.h> using namespace std; int exgcd(int a,int b,int& x,int& y) { int d=a; if(b){ d=exgcd(b,a%b,y,x); y-=(a/b)*x;
阅读全文
摘要:There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xxx , yyy ) means the wave is a rectangle whose vertexes a
阅读全文
摘要:Gerg's Cake Gerg is having a party, and he has invited his friends. p of them have arrived already, but a are runninglate. To occupy his guests, he tr
阅读全文
摘要:Sum of Different Primes Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3684 Accepted: 2252 Description A positive integer may be expressed
阅读全文
摘要:Prime Words A prime number is a number that has only two divisors: itself and the number one. Examples of primenumbers are: 1, 2, 3, 5, 17, 101 and 10
阅读全文
摘要:Less Prime Let n be an integer, 100 n 10000, nd the prime number x, x n, so that n p x is maximum,where p is an integer such that p x n
阅读全文
摘要:Twin Primes Twin primes are pairs of primes of the form (p; p + 2). The term \twin prime" was coined by PaulStckel (1892-1919). The rst few twin prime
阅读全文
摘要:Prime Frequency Given a string containing only alpha-numerals (0-9,A-Z and a-z) you have to count the frequency (thenumber of times the character is p
阅读全文
摘要:错排问题是一种特殊的排列问题。 模型:把n个元素依次标上1,2,3.......n,求每一个元素都不在自己位置的排列数。 运用容斥原理,我们有两种解决方法: 1. 总的排列方法有A(n,n),即n!,设Ai 表示数i在第i个位置的全体排列,显然有Ai =(n-1)!。 同理可得Ai∩Aj=(n-2)
阅读全文
摘要:在计数时,必须注意没有重复,没有遗漏。为了使重叠部分不被重复计算,人们研究出一种新的计数方法,这种方法的基本思想是:先不考虑重叠的情况,把包含于某内容中的所有对象的数目先计算出来,然后再把计数时重复计算的数目排斥出去,使得计算的结果既无遗漏又无重复,这种计数的方法称为容斥原理。 【百度百科】 通常我
阅读全文
摘要:抽屉原理亦称鸽巢原理,该原理可由三种形态描述。 抽屉原理1:把n+1个元素放入n个集合内,必定有一个集合至少含有两个或两个以上元素。 抽屉原理2:把m个元素放进n个集合内,至少有一个集合含有k个元素,其中 k=m/n (n整除m) k=[m/n]+1 (n不整除m)。 抽屉原理3:把无穷多个元素放进
阅读全文
摘要:Bell数: 记Bn是包含n个元素的集合的划分方法的数目。 比如{1,2}可以划分成{{1},{2}}和{{1,2}}两种。 例如:B0=1,B1=1,B2=2,B3=5,B4=15,B5=52。 Bell数递推公式:B0=1,Bn+1=Σ(k=0->k=n) C(n,k)*Bk。 Stirling
阅读全文
摘要:Catalan数又称为卡塔兰数,是组合数学中常出现的一种数列,由数学家欧仁·查理·卡塔兰命名。 令h1=1,h2=1. hn=h1*hn-1+h2*hn-2+.......+hn-1h1(n>=3). 另类递推式: hn=hn-1*(4*(n-1)-2)/((n-1)+1). 由该式又可以得到: h
阅读全文
摘要:Combinations Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11049 Accepted: 5013 Description Computing the exact number of ways that N thi
阅读全文
摘要:Binomial Showdown Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22692 Accepted: 6925 Description In how many ways can you choose k elemen
阅读全文
摘要:题目: Generating permutation has always been an important problem in computer science. In this problemyou will have to generate the permutation of a giv
阅读全文
摘要:ID Codes Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7644 Accepted: 4509 Description It is 2084 and the year of Big Brother has finally
阅读全文
摘要:本题考点:欧拉降幂 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). Input There are mu
阅读全文
摘要:START 参考博客:https://blog.csdn.net/qq_39922639/article/details/77511761 欧拉函数是积性函数的一种,所谓积性函数是指满足,gcd(a,b)&&ƒ(a*b)=ƒ(a)*ƒ(b)的函数,特别的,若gcd(a,b)!=1但是ƒ(a*b)=ƒ
阅读全文
摘要:START 中国剩余定理用于求解线性同余方程组: a = a1 (mod n1) a = a2 (mod n2) a = a3 (mod n3) ........ a = ai (mod ni) 任意ni和nj(i != j)互质,问a的值。 我们可以把a写成a=Σai*ci,(ci待求),这个式子
阅读全文
摘要:START 判断一个数是不是素数可以直接暴力或者是素数筛。 但是对于一个特别大的数,直接用素数筛也有可能TLE。 这个时候就要想点别的办法: 1. 筛选法+试除法 首先用素数筛筛出[2,sqrt(n)+1]的素数,然后用这些素数来判断能不能整除n,如果可以,那么n一定是合数,如果都不行,那么n是素数
阅读全文
摘要:1. gcd: 1 int gcd(int a,int b) 2 { 3 return !b?a:gcd(b,a%b); 4 } exgcd: 1 int exgcd(int a,int b,int& x,int& y) 2 { 3 int d=a; 4 if(b){ 5 d=exgcd(b,a%b
阅读全文
摘要:素数筛 顾名思义,用来筛选素数。 这里介绍两种素数筛: 1.埃氏筛(埃拉托斯特尼筛法) 1 void ass() 2 { 3 memset(u,true,sizeof(u));//u[i]=true表示i是素数 4 for(int i=2; i<=1100000; i++) 5 { 6 if(u[i
阅读全文
摘要:START 为什么需要求逆元?显然对于加减乘运算都会满足: (a+b)%p=(a%p+b%p)%p (a-b)%p=(a%p-b%p)%p (a*b)%p=((a%p)*(b%p))%p但是对于除法而言(a/b)%p!=(a%p)/(b%p),这个可以通过举例验证一下或者可以通过(b%p)可以为0但
阅读全文
摘要:给定一个矩阵,求子矩阵元素之和。 可以暴力遍历,但是一般题目时间上不会允许你这么做。 通过预处理二维数组使得需要子矩阵之和时以O(1)直接求。 输入: for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin >>map[i][j]; 记dp[i][j]表示左上
阅读全文