Segment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description     Silen August does not like to talk with others.She like to find some interesting problems. Today she finds an interesting problem.She…
先放知识点: 莫比乌斯反演 卢卡斯定理求组合数 乘法逆元 快速幂取模 GCD of Sequence Alice is playing a game with Bob. Alice shows N integers a 1, a 2, -, a N, and M, K. She says each integers 1 ≤ a i ≤ M. And now Alice wants to ask for each d = 1 to M, how many different sequences b…
问题描述:求商,不能用乘法,除法,取模运算. 算法思路:不能用除法,那只能用减法,但是用减法,超时.可以用位移运算,每次除数左移,相当于2倍. public class DividTwoIntegers { public int divide(int dividend, int divisor) { if(divisor == 0) return Integer.MAX_VALUE; if(divisor == -1 && dividend == Integer.MIN_VALUE) re…
题目链接: Segment Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) Problem Description       Silen August does not like to talk with others.She like to find some interesting problems. Today she finds an interesting pro…
组合数学推推推最后,推得要求C(n+m,m)%p 其中n,m小于10^9,p小于1^5 用Lucas定理求(Lucas定理求nm较大时的组合数) 因为p数据较小可以直接阶乘打表求逆元 求逆元时,由费马小定理知道p为素数时,a^p-1=1modp可以写成a*a^p-2=1modp 所以a的逆元就是a^p-2, 可以求组合数C(n,m)%p中除法取模,将其转化为乘法取模 即    n!/(m!*(n-m)!)=n!*(m!*(n-m)!)^p-2 求C(n+m,m). n,m<=1000,二维数组递…
Description Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,B,C<2^63). Input There are multiply testcases. Each testcase, there is one line contains three integers A, B and C, separated by a single space. Output For each tes…
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5666 bc(中文):http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=688&pid=1002 题解: 首先可以统计出三角形内所有的点数,(q-2)+(q-3)+...+1=(q-1)*(q-2)/2 其次只要减去被线段割到的点,对于线段xi+yi=q,割到的点有gcd(xi,yi)-1=gcd(xi,q…
猜公式: ans=n/m^(n-1) #include<stdio.h> #include<string.h> struct BigNum { ]; int len; }; int gcd(int a,int b) { ) return a; return gcd(b,a%b); } BigNum mul(BigNum &a,int b) { BigNum c; int i,len; len=a.len; memset(c.num,,sizeof(c.num)); ) {…
Segment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1082    Accepted Submission(s): 398 Problem Description     Silen August does not like to talk with others.She like to find some interesti…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4704 题意:求a^n%m的结果,其中n为大数. S(1)+S(2)+...+S(N)等于2^(n-1),第一次多校都出过吧.然后就是一个裸的大数幂了.. 关于大数的A^B mod C推荐看AC神的两篇文章<如何计算A^B mod C>,<计算a^(n!) mod c>... 当然,这个还以一个更简单的方法,由费马小定理:a^(p-1)=1(mod p),那么a^n=1(mod p)可以…