
数学
文章平均质量分 76
zoro_n
我想走得更远
展开
-
POJ 1845 Sumdiv 【推公式 | 逆元】
题意: 求 a^b 所有因子和。题解: a={p1^x1*p2^x2.....pn^xn} sum(a^b)= (p1^0+p1^1+...+p1^x1).......; 就是算多个等比数列和。 等比数列求和公式 (a^n+1-1)/(a-1) 除法需要逆元,原创 2017-10-06 15:26:22 · 335 阅读 · 0 评论 -
A simple math problem 【矩阵快速幂】
时间限制: 1 Sec 内存限制: 512 MB题目描述Given a number n, you should calculate 123456 . . . 11121314 . . . n module 11.输入A single line with an integer n (0 输出Output one integer, 12345原创 2017-04-19 19:50:08 · 419 阅读 · 0 评论 -
zoj 2316 Matrix Multiplication
点击打开链接题意: 给你一个n*n的矩阵A,然后让你 求 A与 A 的转置矩阵的积。的矩阵所有元素和。题解:题中给的矩阵很特殊,他的转置矩阵和本身相同。那么他们相乘其实就是, 每一行与包括自己的所有行相乘的和。另外 x*x+y*y+2xy =(x+y)^2;所以把每一列所有数加起来,求平方和就是答案。#include#include#原创 2017-04-19 12:08:37 · 674 阅读 · 0 评论 -
cccc L2-018. 多项式A除以B
点击打开链接【转自 Daemoonn 】#include#include#include#include#include#include#include#includeusing namespace std;const int maxn=1e6+100;int x,lena,lenb,maxa=-1,maxb=-1,cntc,cnta;doub转载 2017-04-01 09:09:36 · 3880 阅读 · 0 评论 -
zstuoj 4270: 同源数
点击打开链接给出两个数 A B, 那么s=gcd(A.B)则是 A ,B中公共同源数的最大集合,那么 a= A/s b=B/s ;只要证明 a ,b 和 s 同源就好。那么 求 gcd(a(b),s ) 最后就能得出是否是同源。#include #define ll long longusing namespace std;const int ma原创 2017-03-22 20:43:55 · 404 阅读 · 0 评论 -
tmk找三角
Problem F: tmk找三角Description有一棵树,树上有只tmk。他在这棵树上生活了很久,对他的构造了如指掌。所以他在树上从来都是走最短路,不会绕路。他还还特别喜欢三角形,所以当他在树上爬来爬去的时候总会在想,如果把刚才爬过的那几根树枝/树干锯下来,能不能从中选三根出来拼成一个三角形呢?Input第一行输入一个原创 2017-03-28 23:56:02 · 411 阅读 · 0 评论 -
zstuoj 4274 约素
点击打开链接由素数算数基本定理得 n 能拆分程 x个素数之积。n的因子个数为(a1+1)(a2+1).。。。已知p为质数,所以 如果n为p的奇异数,则一定满足 n开p-1次方 一定是一个素数。所以 当p>3 时, 情况不多,打表就行。 p=3时, 直接对n开方,在判断是否是素数就行。#includ原创 2017-03-22 09:45:49 · 351 阅读 · 0 评论 -
cf 359c Prime Number
点击打开链接题意: 求x^a,,,, 所有数导数之和,分子,分母的最大公约数。题解: sum=a1+a2+a3+......;其实分母就是x^sum;分子为 x^sum-a1+x^sum-a2.......;求出分子的x最小次方就行了。但是形如 2 229 292^29 +2^29 =2^30;所以,当最小次方的个数是x倍数,想上原创 2017-03-11 21:07:56 · 325 阅读 · 0 评论 -
nefu 120 梅森素数 【Lucas-Lehmer】【miller_rabin】
点击打开链接Lucas-Lehmer judge it.#include #include #include #define LL long longusing namespace std;LL p,sum,data[70],t;LL multi(LL a,LL b,LL m){ LL ret=0; while(b>0){原创 2017-02-25 12:49:31 · 308 阅读 · 0 评论 -
nefu 119 组合素数
点击打开链接题意:问一个数能被某个素数整除几次。题解:首先这个题给出了着这个数的大小C(2n,n);也就是(2N)! / (N!*N!);所以易得 2n/p-2[n/p]+2n/p^2-2[n/p^2].....因为最大 p^t=2nso: t=logp(2n);#include#include#include#include原创 2017-02-24 19:49:41 · 251 阅读 · 0 评论 -
room [判断点与线的关系]
点击打开链接时间限制: 1 Sec 内存限制: 64 MB提交: 16 解决: 13[提交][状态][讨论版]题目描述The ACM / ICPC team has a large room, the length and width of which is 10^6 . However, the guys in ACM / ICPC teams are原创 2017-04-19 23:21:36 · 572 阅读 · 0 评论 -
玲珑杯 1131 - 喵哈哈村的几何大师╰☆莣メ誋こ月
点击打开链接Time Limit:1s Memory Limit:256MByteSubmissions:315Solved:70DESCRIPTION╰☆莣メ誋こ月是月大叔的ID,他是一个掌握着429种几何画法的的几何大师,最擅长的技能就是搞事,今天他又要开始搞事了。给你一个等腰三角形,其中A,B原创 2017-06-16 11:39:26 · 358 阅读 · 0 评论 -
cf 822D - My pretty girl Noora 【数论+递推】
点击打开链接题意:这个题意是真的很难,问你n个小姐姐选美,应该怎么排比较的次数最少。 每次比较只能两两比较, 然后让你求出中每个f(i)是多少。 题解: 如果i是素数。那么f(i)=i*(i-1)/2; 否则分的组数越多越有利,又因原创 2017-07-12 00:51:02 · 288 阅读 · 0 评论 -
POJ 1811 Prime Test 【快速判质+因子分解】【模板】
题意: 给你一个数,判断是否是素数,是的话输出prime 不是素数输出最小因子。题解: 快速判质Miller_Rabin 算法, 根据费马小定理 a^(p-1)%p==1 检测是否符合素数性质,当然有伪素数,不过概率很小,多测几次就行了。 然后Pollard 分解因子,顺序是无序的,然后找到最小的那个。原创 2017-10-06 15:19:54 · 352 阅读 · 0 评论 -
HDU - 4992 Primitive Roots 【原根】
题意: 让你求出一个数的全部原根,如果没有,输出-1;题解“: 首先先判断该数有无原根, 一个数x若有原根 则必然满足 n=1,2,4,2p,p^r 若有原根,再暴力枚举找到最小的原根,分解质因数phi(n); 则从2~n-1 中有a 满足 a^ph原创 2017-10-11 10:26:09 · 638 阅读 · 0 评论 -
POJ - 2417 Discrete Logging 【bsgs模板】
点击打开链接题意: xy≡z(modp) 已知x,z,p 。 求y。题解: xy≡z(modp)根据费马小定理:xp−1≡1。 如果y已经枚举到了p-1了,继续枚举的话就会产生循环。 所以,在暴搜中y的枚举范围就是0……p-1把y分成p−1−−−−√分原创 2017-10-07 21:31:22 · 370 阅读 · 0 评论 -
二次剩余Cipolla算法 【转载a_crazy_czy】
大佬博客传送门首先我们要弄清楚什么叫二次剩余,其实就是对于给定的p(p∈P)和n,如果有x满足x2≡n(modp),那么n在模p意义下就是二次剩余。说白了就是模意义下能否开根号。 我们只讨论p为奇素数的情况。 我们先定义Fp,这是一个数域,其实就是0到p−1这p个数与模p意义下加减乘除运算构成的集合。定理1:对于x2≡n(modp),总共有p−12个的n能使转载 2017-10-07 15:46:15 · 655 阅读 · 0 评论 -
hdu 6053 TrickGCD 【容斥&筛法|莫比乌斯】
点击打开链接题意: 给你一个a序列,让你自己构造b序列,b序列需要满足每个数 bi=2. 问你这样的序列有多少个。题解: 1,筛法 枚举gcd的值,bi的取值最大ai. 所以每个位置有ai/gcd种情况, .然后把这种情况全部弄成一块,快速幂,logn, 最后原创 2017-07-28 17:33:27 · 457 阅读 · 0 评论 -
POJ 1556 The Doors【单源最短+线段相交】
点击打开链接题意:给你一个10*10的方格, 然后在里面放不超过十堵墙。然后问你从 (0,5)->(10,5)的最短路。题解:最短路,但是建图非常恶心,需要判断线段之间是否相交。不相交才能建边。判断两线段是否相交。模板double mult(Point a, Point b, Point c) { return (a.x-原创 2017-04-13 14:21:40 · 299 阅读 · 0 评论 -
hdu 5726 GCD 【RMQ+st】
点击打开链接题意: 给你一个序列有n个数,有m次查询,每次查询询问l到r区间内 所有数的gcd是多少,并且输出所有区间内gcd值更与该gcd的区间个数。题解: 想写这个题,首先要知道gcd的一个特性,一个数字n他的gcd是log级的,那这样就可以暴力了枚举了,并且直接用map记录每个gcd值出现的个数直接输出。原创 2017-07-18 10:58:54 · 245 阅读 · 0 评论 -
玲珑 1144 - 数论你还会快速幂 【数论】【O(1)乘法】
点击打开链接DESCRIPTION今天HHHH在学数论,他看到一个很优美的式子:∑ni=1ik mod p∑i=1nik mod pINPUT第一行是一个整数T(1≤T≤1000)T(1≤T≤1000),表示有TT组数据对于每组数据输入一行3个整数n,k,p(1≤n≤1018,0≤k≤101原创 2017-07-17 09:34:49 · 1209 阅读 · 0 评论 -
hdu 2446 Shell Pyramid
点击打开链接题意: 题意很迷,看了很久才看懂。 他要堆炮弹,怎么堆呢, 递增的三角形的堆,例如 1 2 5 11 .。。。3 4 6 7 8 9 10 然后给你一个炮弹编号, 问你在原创 2017-07-04 11:23:45 · 358 阅读 · 0 评论 -
nefu 118 jisuan N! 0 de ge shu
#include #include #include #define LL long longusing namespace std;int main(){ int T; LL n; scanf("%d", &T); while(T--){ scanf("%lld" ,&n); LL five=5,cnt=0;原创 2017-02-23 20:07:25 · 325 阅读 · 0 评论 -
POJ 2689 Prime Distance
点击打开链接题意:给你一个区间。求这个区间内相邻最近的两个素数和相邻最远的两个素数分别是多少。题解:很明显直接找出l,u之间的素数,然后遍历一遍。就能求出结果。但这个题l,u,范围比较大。直接筛法打表肯定不能实现,又已知 u-l 已知1e32内的要么是素数,要么是能被 sqrt(1e32)整除的数,即 l,u中的所有非素数的因子都在sqrt(1e32)之原创 2017-02-22 21:17:50 · 167 阅读 · 0 评论 -
hdu 5826 physics
Problem DescriptionThere are n balls on a smooth horizontal straight track. The track can be considered to be a number line. The balls can be considered to be particles with the same mass.At t原创 2016-08-11 20:26:06 · 453 阅读 · 0 评论 -
zzuli 1902 985的因子对难题
Description985有n个正整数,他想知道存在多少个不同的因子对(a[i], a[j])使得1 特别地,他认为(a[i],a[j])与(a[j],a[i])是一样的因子对。Input第一行输入一个整数t,代表有t组测试数据。每组数据占两行,第一行输入一个n代表元素个数,下面一行输入n个整数a[]。注:1 Output一个整原创 2016-08-30 17:44:37 · 232 阅读 · 0 评论 -
hdu 5858 Hard problem
Problem Descriptioncjj is fun with math problem. One day he found a Olympic Mathematics problem for primary school students. It is too difficult for cjj. Can you solve it?Give you the side l原创 2016-08-19 10:57:01 · 294 阅读 · 0 评论 -
zzuli 1893 985的数学难题
Description985有n个正整数,他想快速知道下面函数的返回值int a[N+1];long long Solve() { int i, j; long long ans = 0; for(i = 1; i for(int j = i + 1; j ans += a[i] + a[j] + (a[i] ^ a[j]原创 2016-08-06 10:01:49 · 275 阅读 · 0 评论 -
hdu 5742 It's All In The Mind
Problem DescriptionProfessor Zhang has a number sequence a1,a2,...,an. However, the sequence is not complete and some elements are missing. Fortunately, Professor Zhang remembers some properties of th原创 2016-07-21 22:09:32 · 267 阅读 · 0 评论 -
hdu 5734 Acperience
Problem DescriptionDeep neural networks (DNN) have shown significant improvements in several application domains including computer vision and speech recognition. In computer vision, a particular原创 2016-07-21 22:05:40 · 264 阅读 · 0 评论 -
hdu 5776 sum (鸽巢原理)
Problem DescriptionGiven a sequence, you're asked whether there exists a consecutive subsequence whose sum is divisible by m. output YES, otherwise output NO InputThe first line of t原创 2016-07-31 17:56:19 · 355 阅读 · 0 评论 -
poj 2965 The Pilots Brothers' refrigerator
DescriptionThe game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to open a refrigerator.There are 16 handles on the refrigerator door. Every handle can原创 2016-07-27 19:19:39 · 256 阅读 · 0 评论 -
hdu 5753 Permutation Bo
Problem DescriptionThere are two sequences h1∼hn and c1∼cn. h1∼hn is a permutation of 1∼n. particularly, h0=hn+1=0.We define the expression [condition] is 1 when condition is True,is 0原创 2016-07-26 17:55:08 · 365 阅读 · 0 评论 -
poj 1061 青蛙的约会
Description两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面。它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止。可是它们出发之前忘记了一件很重要的事情,既没有问清楚对方的特征,也没有约定见面的具体位置。不过青蛙们都是很乐观的,它们觉得只要一直朝着某个方向跳下去,总能碰到对方的。但是除非这两只青蛙在同一时间跳到同一点上,不然是永远都不可能碰面原创 2016-10-13 23:11:39 · 275 阅读 · 0 评论 -
hdu 5974 A Simple Math Problem
点击打开题目链接已知a+b 和 a*b 所以由此可以直接表示。输入x,y 所以gcd(x,y)==gcd(a,b)所以 联立 a+b=x a*b/gcd(x,y)=y最终 得出来一个二元一次方程。首先 方程要有解,然后判断是否成立。#include#define LL long longusing namespace std;LL gcd(LL a原创 2016-11-06 22:58:31 · 553 阅读 · 0 评论 -
nsoj 4714 次方求模
点击打开题目链接快速幂。如果幂是偶数,除2 底乘2否则 结果乘底#include#define maxn 11111#define LL long longusing namespace std;int main(){ int T; LL a,b,c; scanf("%d",&T); while(T--){ scanf("%ll原创 2016-11-18 17:11:38 · 250 阅读 · 0 评论 -
玲珑杯 #round 9 1084 - Check-in Problem
点击打开链接这个题好纠结啊。开始根本没有理解题意,最后才发现,p一定是质数,,,,,这个当时一直没发现。已知n 和p的范围,由素数算数基本定理得 n 能拆分程 x个素数之积。n的因子个数为(a1+1)(a2+1).。。。已知p为质数,所以 如果n为p的奇异数,则一定满足 n开p-1次方 一定是一个素数。所以 当p>3 时, 情况不多,打表就行。原创 2017-02-21 21:59:33 · 199 阅读 · 0 评论 -
hdu 1495 非常可乐
点击打开链接题意: 给你三个杯子。 a,b,c. 且 a=b+c;问你能不能将a里面的水平分。能的话求出最少次数。不能输出NO ;很明显奇数是一定gg的。直接暴力bfs来一发。每次可走的路可分为6条。 a->ba->cb->a......就过了。另外还有数学规律:原创 2016-12-27 13:02:09 · 343 阅读 · 0 评论 -
玲珑oj 1071 - Boring Game
点击打开链接题意,给你两个序列,然后你有一种操作方法,不论操作多少次,只要能将上面的数列变成下面的数列就YES 否则no。对an操作,则 (ai-1, ai, ai+1)->(ai-1 + ai, -ai, ai+1 + ai)然后发现,其前缀和为,(si-1, si, si+1)->(si, si-1, si+1)返原创 2016-12-24 18:01:27 · 296 阅读 · 0 评论 -
hdu 5902 GCD is Funny
Problem DescriptionAlex has invented a new game for fun. There are n integers at a board and he performs the following moves repeatedly:1. He chooses three numbers a, b and c written at th原创 2016-09-25 12:32:57 · 760 阅读 · 0 评论