HDU 2035 快速幂取模

来源:互联网 发布:Python log日志的级别 编辑:程序博客网 时间:2024/04/29 13:26

HDU 2035




题解 : 模板题, 快速幂入门.



code: 

/*adrui's submissionLanguage : C++Result : AcceptedLove : llFavorite : Dragon BallsStanding in the Hall of Fame*/#include<cstdio>#include<cstring>#include<algorithm>#include<queue>#include<iostream>#include<bitset>#include<map>using namespace std;#define M(a, b) memset(a, b, sizeof(a))#define mid ((l + r) >> 1)#define ls rt << 1, l, mid#define rs rt << 1|1, mid + 1, r#define lowbit(x) (x & (-x))#define LL long long#define REP(n) for(int i = 1; i <= n; i++)#define debug 0#define mod 1000int n, m;int fast_multi(int a, int b) {int ans = 0;while (b) {if (b & 1) ans = (ans + a) % mod;a = (a + a) % mod;b >>= 1;}return ans;}int fast_mod() {int res = 1;while (m) {if (m & 1) res = fast_multi(res, n);n = fast_multi(n, n);m >>= 1;}return res;}int main() {#if debugfreopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);#endif //debugwhile (~scanf("%d%d", &n, &m), n + m) {printf("%d\n", fast_mod());}return 0;}



1 0
原创粉丝点击