随笔分类 -  数学

摘要:Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD(x, y) = k. GCD(x, y) means the greatest common divisor of x and y. Sin 阅读全文
posted @ 2017-05-08 22:13 cdongyang 阅读(241) 评论(0) 推荐(0)
摘要:1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long LL; 4 const int N=1e6+10; 5 const int INF=0x3f3f3f3f; 6 int cas=1,T; 7 int c[N]; 阅读全文
posted @ 2017-05-08 22:09 cdongyang 阅读(193) 评论(0) 推荐(0)
摘要:1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long LL; 4 void gcd(LL a, LL b, LL &d, LL &x, LL &y) 5 { 6 if (!b) 7 { 8 d = a; 9 x = 阅读全文
posted @ 2017-05-08 19:57 cdongyang 阅读(229) 评论(0) 推荐(0)
摘要:给出n,m,k,求1~n中前m个正好有k个在原来位置的种数(i在第i个位置) 做法:容斥,先选出k个放到原来位置,然后剩下m-k个不能放到原来位置的,用0个放到原来位置的,有C(m-k,0)*(n-k)!种 - 1个放原来位置的,有C(m-k,1)*(n-k-1)!种+...-... 1 #incl 阅读全文
posted @ 2016-07-14 19:58 cdongyang 阅读(217) 评论(0) 推荐(0)
摘要://容斥原理,c[i]表示i当前要算的次数,复杂度和第二层循环相关 O(nlogn~n^2) LL in_exclusion(int n,int *c) { for(int i=0;i<=n;i++) c[i]=1; //不一定是这样初始化,要算到的才初始化为1 LL ans=0; for(int 阅读全文
posted @ 2016-04-18 22:35 cdongyang 阅读(1938) 评论(0) 推荐(0)
摘要:1 /* 2 1 3 126 223092870 4 210 330 390 462 510 546 570 690 714 770 798 858 910 966 1122 1155 1190 1254 1326 1330 1365 1430 1482 1518 1610 1785 1794 18 阅读全文
posted @ 2016-04-07 23:34 cdongyang 阅读(247) 评论(0) 推荐(0)
摘要:input T <=10 n k n<=1000 k<=10^18 a1,a2,...an |ai|<=10^18 output (a1^k+a2^k+...+an^k)%10^10+7 Sample Input 2 Sample Output 6 60074 做法:快速幂+__int128,需注意 阅读全文
posted @ 2016-03-25 23:39 cdongyang 阅读(196) 评论(0) 推荐(0)
摘要:input 样例个数T <=10000 每个样例一个n(2<=n<=10^8) output lcm(1,2,...,n)%2^32 Sample Input 5 10 5 200 15 20 Sample Output 2520 60 2300527488 360360 232792560做法:质 阅读全文
posted @ 2016-03-25 22:02 cdongyang 阅读(368) 评论(0) 推荐(0)
摘要:inputT 1 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 #define... 阅读全文
posted @ 2015-12-18 14:25 cdongyang 阅读(792) 评论(0) 推荐(0)
摘要:inputn 1 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 #includ... 阅读全文
posted @ 2015-12-18 13:52 cdongyang 阅读(518) 评论(0) 推荐(0)
摘要:inputn 1g(i) 0 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 #... 阅读全文
posted @ 2015-12-16 15:06 cdongyang 阅读(398) 评论(0) 推荐(0)
摘要:inputT 1=0)步走到(x,y),只能从(x,y)走到(x,y+lcm(x,y))/(x+lcm(x,y),y)标准解:从(x,y0)走到(x,y),则设x=ag,y0=bg,g=gcd(x,y0),有y=bg+abg=(a+1)bg,因为a,b互质,a,(a+1)互质,所以a和(a+1)b... 阅读全文
posted @ 2015-12-16 14:56 cdongyang 阅读(296) 评论(0) 推荐(0)
摘要:input1 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 13 using ... 阅读全文
posted @ 2015-11-02 21:52 cdongyang 阅读(279) 评论(0) 推荐(0)
摘要:input长度不大于3*10e5的数字串output不含前导0的能整除64的字串的个数(0算一个,064不算)一般数组中找能整除一个数的字串都是用取余来做的用一个a[64]来存下从1-i位累加到第i位的余数为0-63的个数,每次都加上余数为0的个数,第一位为0的只统计一次,不加入a数组中 1 #in... 阅读全文
posted @ 2015-11-02 17:11 cdongyang 阅读(169) 评论(0) 推荐(0)
摘要:MZL's xorTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 911Accepted Submission(s): 589Problem D... 阅读全文
posted @ 2015-10-13 20:46 cdongyang 阅读(222) 评论(0) 推荐(0)
摘要:Team FormationTime Limit:3 Seconds Memory Limit:131072 KBFor an upcoming programming contest, Edward, the headmaster of Marjar University, is forming ... 阅读全文
posted @ 2015-10-13 20:30 cdongyang 阅读(145) 评论(0) 推荐(0)
摘要:条件概率,r个人买东西的条件下第i个人买东西的概率P(Ai|B)。而P(Ai|B)=P(AiB)/P(B),其中P(AiB)表示事件Ai与事件B同时发生的概率,p(B)为B事件发生的概率 第一个样例 3 2 0.10 0.20 0.30 p(B)为两个人买东西的概率,p(AiB... 阅读全文
posted @ 2015-10-11 21:31 cdongyang 阅读(269) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 #include 4 5 using namespace std; 6 7 unsigned int r,sum,p,q; 8 unsigned int st[50010][2]; 9 10 unsigned gcd(unsigned a,un... 阅读全文
posted @ 2015-10-11 16:43 cdongyang 阅读(173) 评论(0) 推荐(0)
摘要:题目意思为解码字符串,要输出第n个回文字符串,因为对称关系,前一半确定了,后一半也就跟着确定了,所以n其实就是前一半字符串的编码,还要减去1,直接解码出来再复制给后半即可 1 #include 2 #include 3 #include 4 5 using namespace std... 阅读全文
posted @ 2015-10-05 16:55 cdongyang 阅读(169) 评论(0) 推荐(0)
摘要:只能往一个方向倒,如c1=3,c2=5,a b从0 0->0 5->3 2->0 2->2 0->2 5->3 4->0 4->3 1->0 1->1 5->3 3->0 3->0 0,又回到了0 0,而且倒着推回去正好是c1一直往c2倒,因为0*c2%c1->1*c2%c1->...->c1*c2... 阅读全文
posted @ 2015-10-04 11:35 cdongyang 阅读(236) 评论(0) 推荐(0)