2012年6月10日

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2151水View Code #include <stdio.h>#include <string.h>int n,p,m,t ;int dp[110][110] ;int main(){ while(~scanf("%d%d%d%d",&n,&p,&m,&t)) { memset(dp,0,sizeof(dp)) ; dp[0][p]=1 ; for(int i=0;i<=m;i++) for(int j=1;j<=n;j 阅读全文
posted @ 2012-06-10 19:35 LegendaryAC 阅读(130) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2973威尔逊定理,详情参见数论四大定理。从这道题应用的层面讲,我们只需要知道若p为素数,则p可整除(p-1)!+1。有上面的结论这道题就解决了,3k+7为素数则答案加1,为非素数则不变。(代数式简单变化一下很容易看出来,此处不赘述)为了防止超时,提前把答案打表打出来就好。输入输出挂,果断刷到第一。View Code #include <iostream>using namespace std ;bool prime[3000008] ;int ans[1000001] ;inline bool s 阅读全文
posted @ 2012-06-10 02:59 LegendaryAC 阅读(397) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1395枚举x复杂度可以处理成O(n),由于我是个sb,所以给弄成O(nlogn)了。这里用的方法基于欧拉定理。欧拉定理表明,若n,a为正整数,且n,a互质,(a,n) = 1,则a^φ(n) ≡ 1 (mod n)。我们处理的当然是(2,n)=1的情况,枚举欧拉函数的因子即可View Code #include <stdio.h>__int64 qpow(int a,__int64 b,int r){ __int64 ans=1,buff=a; while(b) { if(b&... 阅读全文
posted @ 2012-06-10 00:55 LegendaryAC 阅读(232) 评论(0) 推荐(0) 编辑