
ACM
浪在冰城
原谅我一生放荡不羁爱自由 个人微信公众号:KeepYourAims
展开
-
判断输入的2个整型数据是否在0-100之间,如果是则求和,如果不是则报错是不合法的输入
# -*- coding: utf-8 -*-"""Created on Mon Feb 24 20:46:49 2020@author: Administrator题目:判断输入的2个整型数据是否在0-100之间,如果是则求和,如果不是则报错是不合法的输入"""a,b = map(int, input('输入2个0-100之间的整数:').split())if 0<=...原创 2020-03-02 19:51:26 · 803 阅读 · 0 评论 -
母函数
定义(摘自百度百科):对于任意数列a0,a1,a2...an 即用如下方法与一个函数联系起来:G(x) = a0 + a1x + a2x^2 + a3x^3 +....+ anx^n则称G(x)是数列的母函数。这个母函数有啥用呢?先看一一个简单的例子,假设你有一角钱,二角钱,三角钱,四角钱各一张。那么你要买一个5角钱的东西,不找零,有几种方式?通过枚举,我们不难发现,其实有...原创 2019-12-21 12:19:08 · 1769 阅读 · 0 评论 -
容斥原理
题目描述:给定A, B, N (1 <= A <= B <= 10^15,1<=N <= 10^9).求[A,B]区间内与N互素的数的个数步骤: (1)将问题化为求1~B,1~A中与N互素的数的个数的差,当然考虑到A可能与N互素的情况,在实际操作时, 即求1~A时最好改成求1~A-1(包含A-1); (2)...原创 2019-12-19 16:30:48 · 827 阅读 · 0 评论 -
最大公约数之和
Given the value of N, you will have to find the value of G. The meaning of G is given in the following codeG=0;for(i=1;i<N;i++) for(j=i+1;j<=N;j++) G+=gcd(i,j);#include<ios...原创 2019-12-19 16:30:56 · 862 阅读 · 0 评论 -
組合数取模
组合数取模就是求C(n,m)%p的值,当然根据n,m和p的取值范围不同,采取的方法也不一样。1.P是素数:#include <iostream>#include <string.h>#include <stdio.h>using namespace std;typedef long long LL;LL n,m,p;LL quick_mod...原创 2019-12-19 16:31:07 · 953 阅读 · 0 评论 -
威尔逊定理
在初等数论中,威尔逊定理给出了判定一个自然数是否为素数的充分必要条件。即:当且仅当p为素数时:( p -1 )! ≡ -1 ( mod p ),但是由于阶乘是呈爆炸增长的,其结论对于实际操作意义不大。即:若p为质数,则p可整除(p-1)!+1。...原创 2019-12-19 16:31:15 · 1062 阅读 · 0 评论 -
素数的判定
3.素数判定(1)试除法:bool isprime(int n){int i;for(i=2;i<=(int)sqrt(n*1.0);i++) if(n%i==0) return false;return true;}bool isprime(int n){if(n==2) return true;if(n==1||(n&1)==...原创 2019-12-19 16:31:25 · 886 阅读 · 0 评论 -
数的分解
求一个数的质因子:#include<stdio.h>int a[20];int main(){ int n,i,num=0; scanf("%d",&n); for (i=2;i*i<=n;i++) { if (n%i==0) a[num++]=i; while(n%i==...原创 2019-12-19 16:31:34 · 1086 阅读 · 0 评论 -
任意进制转换
每组输入数据共有三行,第一行是一个正整数,表示需要转换的数的进制n(2≤n≤16),第二行是一个n进制数,若n>10则用大写字母A~F表示数码10~15,并且该n进制数对应的十进制的值不超过1000000000,第三行也是一个正整数,表示转换之后的数的进制m(2≤m≤16)。16FF2#include <iostream>#include <cstring...原创 2019-12-19 16:31:46 · 1537 阅读 · 0 评论 -
求因子和与因子个数
求因子和与因子个数(包含1和本身)所有因子个数τ(n)与所有因子的和σ(n)都是乘(积)性函数。定义1:因子和函数σ定义为整数n的所有正因子之和,记为σ(n)。定义2:因子个数函数τ定义为正整数n的所有正因子个数,记为τ(n)。定理1:设p是一个素数,a是一个正整数,那么 σ(n)=1+p+p^2+……+p^a=【p^...原创 2019-12-19 16:31:47 · 1833 阅读 · 0 评论 -
求解模线性方程组(中国剩余定理)
求解模线性方程组(中国剩余定理) x=a1 mod m1 x=a2 mod m2 ...... x=an mod mn 其中,a[],m[]已知,m[i]>0且m[i]与m[j]互质,求x.普通的中国剩余定理要求所有的m是互素有整数解。并且在模下的解是唯一的,解为int CRT(int a[],int m[],int n){ int M = 1; i...原创 2019-12-19 16:34:58 · 1304 阅读 · 0 评论 -
裴蜀定理
给出a,b,N,找出自然数x,y满足:N-(a*x+b*y)的值最小,如果有多组解是,输出任意一组。#include <iostream>#include <string.h>#include <stdio.h>using namespace std;void Work(int a,int b,int n){ if(a == 1) ...原创 2019-12-21 12:18:41 · 1534 阅读 · 0 评论 -
欧拉函数
欧拉函数百度百科:#include<stdio.h>#include<stdlib.h>int eular(int n){ int ret=1,i; for(i=2;i*i<=n;i++) { if(n%i==0) { n/=i,ret*=i-1; whi...原创 2019-12-21 12:18:49 · 1561 阅读 · 0 评论 -
欧几里得及扩展欧几里得
1.欧几里得 求最大公约数,最小公倍数(1)递归的写法:int gcd(int a,int b) {return b?gcd(b,a%b):a;}(2)辗转相除法:int gcd(int a,int b){if(a<b) return gcd(b,a);int r;while(b) {r=a%b;a=b;b=r;}return a;}(3)stein+欧几里...原创 2019-12-18 01:04:19 · 811 阅读 · 0 评论 -
逆元+快速幂
求逆元ax=1 (mod m) x是a的逆元(1)用扩展欧几里得求int Inv(int a,int m){ int r,x,y; r=exgcd(a,m,x,y); if(r==1) return (x%m+m)%m; return -1;}(2)用快速幂取模求a*a^(p-2)=a^(p-1)=1 (mod p) p必须为素数,a的逆元是a^(p-2);int p...原创 2019-12-18 01:03:49 · 872 阅读 · 0 评论 -
母函数
定义(摘自百度百科):对于任意数列a0,a1,a2...an 即用如下方法与一个函数联系起来:~G(x) = a0 + a1x + a2x^2 + a3x^3 +....+ anx^n则称G(x)是数列的母函数。那我们怎么写代码来计算呢?我以(1+x)*(1+x^2)*(1+x^3)*(1+x^4)为例子://计算(1+x)*(1+x^2)*(1+x^3)*(1+x^4)#inclu...原创 2019-12-18 01:03:15 · 809 阅读 · 0 评论 -
莫比乌斯·反演
给一个正整数n,其中n<=1e7,,求使得gcd(x,y)为质数的的(x,y)个数.1<x,y<n.#include <iostream>#include <string.h>#include <stdio.h>#include <bitset>using namespace std;typedef long long...原创 2019-12-18 01:02:43 · 810 阅读 · 0 评论 -
连分数
Sample Input75 3465 600 0Sample OutputCase 1:75 / 34..........1......2.+.-------------............1........4.+.---------..............1..........1.+.-----................1............5...原创 2019-12-18 01:02:11 · 910 阅读 · 0 评论 -
快速幂取余
快速模乘 a*b%pint mul(int a,int b){int r=0;while(b){ if(b&1) r=(r+a)%p; a=(a<<1)%p; b>>=1;}return r;}原创 2019-12-18 01:01:13 · 270 阅读 · 0 评论 -
卡塔兰数
卡特兰数又称卡塔兰数,英文名Catalan number。是组合数学中一个常出现在各种计数问题中出现的数列。以比利时的数学家欧仁·查理·卡塔兰 (1814–1894)的名字来命名,其前几项为 :1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440,9694845, 35357670...原创 2019-12-18 01:00:42 · 882 阅读 · 0 评论 -
关于方程a^x=1(mod m)的最小x解
定理:设gcd(a,m)=1,必有正整数x,使得a^x=1(mod m),且设满足等式的最小正整数为x0,必满足x0|phi(m).注意m>1.否则如果gcd(a,m)!=1,则方程a^x=1(mod m)没有解。典型题目:HDU1395,HDU3307,POJ3696前面两题很简单,下面我们来分析POJ3696.题目:The Luckiest number题意:求出...原创 2019-12-18 01:00:06 · 600 阅读 · 0 评论 -
哥的巴赫猜想
哥德巴赫猜想:任何一个大于2的偶数,都可以表示为两个素数之和。另外还有,任何一个大于5的奇数都可以表示为三个素数之和。给定一个正整数n,范围是[2,10^9],把n表示为若干个素数的和,输出一种方案,使得素数的个数最少。#include <iostream>#include <string.h>#include <stdio.h>#include &...原创 2019-12-18 00:59:41 · 289 阅读 · 0 评论 -
反素数模板
Maximum Number Of DivisorsYou are given an integer P, please find an integer K that has the maximum number of divisors under the condition that K <= P.Note that if multiple integers have the sam...原创 2019-12-17 23:52:53 · 196 阅读 · 0 评论 -
法雷级数
法雷级数,是指每一行从0/1开始,以1/1结尾,其它数自左至右将所有的真分数按增加顺序排列;第n行是由所有分母小于或等于n的真分数组成,我们称为n阶法雷级数。R.亨斯贝尔格著李忠翻译的《数学中的智巧》一书,介绍了法雷级数。如下表:F1: 0/1 1/1F2: 0/1 1/2 1/1F3: 0/1 1/3 1/2 2/3 1/1F4: 0/1 1/4 1/3 1/2 2/3 3/4 1...原创 2019-12-17 23:52:22 · 246 阅读 · 0 评论 -
二次同余方程的解
今天要讨论的问题是解方程x^2恒等於n(mod p),其中p是奇质数。#include <stdio.h>#include <stdlib.h>#include <string.h>#include <algorithm>#include <iostream>#include <math.h>using nam...原创 2019-12-17 23:51:46 · 815 阅读 · 0 评论 -
博弈论
题意:有3堆石子,石子数量分别为a,b,c,有两个玩家,每次只能从任意一堆中取f个,这里的f只能为fibnacci数,问是先手胜还是先手败.分析:由于石子的数量都在1000以内,那么我们可以先预处理出1000以内的SG函数值,然后对于3堆石子,我们进行异或,如果为0说明先手必败,否则必胜,当然求SG函数的值用深搜就行了.#include <iostream>#include ...原创 2019-12-17 23:51:11 · 193 阅读 · 0 评论 -
伯努利数和自然数幂和
T(n) = n^k,S(n) = T(1) + T(2) + ...... T(n)。给出n和k,求S(n)。例如k = 2,n = 5,S(n) = 1^2 + 2^2 + 3^2 + 4^2 + 5^2 = 55。由于结果很大,输出S(n) Mod 1000000007的结果即可。#include <iostream>#include <string.h>#...原创 2019-12-17 23:50:32 · 347 阅读 · 0 评论 -
毕达哥拉斯三元组的解
对于一个方程: x^2 + y^2 = z^2,他两两互质的正整数解满足一下条件1. x = 2*m*n ,y = m^2 - n^2 ,z = m^2 + n^22. gcd( m , n) =1, m > n , m 与 n 的奇偶性不同( 2*m*n )^2 + ( m^2 - n^2 )^2 = ( m^2 + n^2 )显然成立。下面我们来看一个例题 POJ 1305 ...原创 2019-12-17 23:50:06 · 531 阅读 · 0 评论 -
x^A=B(mod C)的解 (离散对数与原根)
x^A=B(mod C)的解 (离散对数与原根)#include <iostream>#include <string.h>#include <algorithm>#include <stdio.h>#include <math.h>#include <bitset>#include <map>u...原创 2019-12-17 23:49:23 · 391 阅读 · 0 评论 -
n的二进制表示中1的个数的乘积
设 sum(i) 表示 i 的二进制表示中 1 的个数。给出一个正整数 N ,求 sum(1)至sum(N) 的乘积。#include <iostream>#include <string.h>#include <stdio.h>using namespace std;typedef long long LL;const int N=100005...原创 2019-12-17 23:48:50 · 240 阅读 · 0 评论 -
n%i之和
给定一个n,注意这里n小于10^12,求从i=1到n, n%i之和import java.math.BigInteger;import java.util.Scanner;import java.math.*;public class Main{ public static BigInteger Solve(long n) { BigI...原创 2019-12-17 23:48:09 · 340 阅读 · 0 评论 -
landau函数
对于所有非负整数n,兰道函数g(n)定义为对称群S_n的所有元素的秩之中,最大的一个。或者说,g(n)是n的所有整数分拆之中的最小公倍数。例如 5=2+3,lcm(2,3)=6,没有其他5的分割方式能得出一个更大的最小公倍数,故此g(5)=6有一个正整数n, n的范围是[0,1000], 把它拆分成若干个数的和,使得它们的最小公倍数最大,求最大的最小公倍数S。import java.m...原创 2019-12-17 23:47:40 · 837 阅读 · 0 评论 -
HDU 3293:sort
Problem DescriptionAs is known to all, long long ago sailormoon once was an association of fighters. Till now, sailormoon is also an association of girls. Owe to some unknown reasons, girls are nece原创 2016-07-11 15:17:13 · 464 阅读 · 0 评论 -
Poj 1068:Parencodings
DescriptionLet S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways:q By an integer sequence P = p1 p2...pn where pi is the number of left parentheses bef原创 2016-07-02 15:32:29 · 517 阅读 · 0 评论 -
poj 1753:Flip Game
DescriptionFlip game is played on a rectangular 4x4 field with two-sided pieces placed on each of its 16 squares. One side of each piece is white and the other one is black and each piece is lying e原创 2016-07-02 11:36:38 · 407 阅读 · 0 评论 -
HDU - 4112 Break the Chocolate
Break the ChocolateProblem DescriptionBenjamin is going to host a party for his big promotion coming up.Every party needs candies, chocolates and beer, and of course Benjamin has prepa原创 2016-06-29 19:11:44 · 498 阅读 · 0 评论 -
Timus 1104. Don’t Ask Woman about Her Age
Mrs Little likes digits most of all. Every year she tries to make the best number of the year. She tries to become more and more intelligent and every year studies a new digit. And the number she make原创 2016-07-30 19:10:17 · 880 阅读 · 0 评论 -
任意进制转换
代码:每组输入数据共有三行,第一行是一个正整数,表示需要转换的数的进制n(2≤n≤16),第二行是一个n进制数,若n>10则用大写字母A~F表示数码10~15,并且该n进制数对应的十进制的值不超过1000000000,第三行也是一个正整数,表示转换之后的数的进制m(2≤m≤16)。16FF2#include #include #include using namespac原创 2016-10-04 17:07:20 · 833 阅读 · 0 评论 -
数学训练----数论Sum
DescriptionInput2Output2Hint1. For N = 2, S(1) = S(2) = 1.2. The input file consists of multiple test cases.题目分析:这道题就是x1+x2+x3+···+xn=N,求有几种组合方法。利用数学方法中的“隔板法”,不难知道结果就是C原创 2016-10-13 13:30:10 · 850 阅读 · 0 评论 -
数学训练----数论-寒假安排
DescriptionOne day I was shopping in the supermarket. There was a cashier counting coins seriously when a little kid running and singing "门前大桥下游过一群鸭,快来快来 数一数,二四六七八". And then the cashier put the原创 2016-10-14 16:41:39 · 395 阅读 · 0 评论