摘要: 无穷的公式 a/b%mod=a*(b^(mod-2))%mod 表示a乘b的(mod-2)次方 mod是素数 即s[n]/(s[n-m]*s[m])%mod==s[n]*pow(s[n-m],mod-2)*pow(s[m],mod-2)%mod 因为幂比较大 所以要用大指数幂的公式 阅读全文
posted @ 2016-08-11 11:07 爱记录一切美好的微笑 阅读(167) 评论(0) 推荐(0) 编辑
摘要: #include #include #include #include #include #include using namespace std; typedef long long LL; const int maxn=1000007; const int INF=0x3f3f3f3f; const int mod=1000003; LL a[maxn], vis[maxn],... 阅读全文
posted @ 2016-08-11 10:54 爱记录一切美好的微笑 阅读(138) 评论(0) 推荐(0) 编辑
摘要: 快速幂取模 用法:用于求解 a 的 b 次方,而b是一个非常大的数,用O(n)的复杂度会超时。那么就需要这个算法,注意它不但可以对数求次幂,而且可用于矩阵快速幂。 假如求 x ^ n 次方 我们可以把 n 表示为 2^k1 + 2k2 + 2^k3....,可以证明所有数都可以用前式来表示。(其实就 阅读全文
posted @ 2016-08-11 09:58 爱记录一切美好的微笑 阅读(126) 评论(0) 推荐(0) 编辑