C小加

厚德 博学 求真 至善 The bright moon and breeze
posts - 145, comments - 195, trackbacks - 0, articles - 0
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

次方求模模板

Posted on 2012-04-06 14:51 C小加 阅读(387) 评论(0)  编辑 收藏 引用 所属分类: 模板
template<class IntType>
inline IntType ModPow(IntType m,IntType n,IntType p) //m的n次方模p
{
    if(n==0) return 1;
    if (n==1) return m%p;
        IntType tmp=ModPow(m,n>>1,p);
    return (tmp*tmp%p)*((n%2?m:1)%p)%p;
}

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理