一.题目背景 已知底数a,指数b,取模值mo 求ans = ab % mo 二.朴素算法(已知可跳过) ans = 1,循环从 i 到 b ,每次将 ans = ans * a % mo 时间复杂度O(b) void power(int a,int b,int mo) { int i; ans=; ;i<=b;i++) { ans*=a; ans%=mo; } } 三.快速幂 先讨论无需取模的 当b为偶数时:ab=a(b/2)*2=(a2)b/2 当b为奇数时:ab=a*ab-1=a*(a2)…
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec Problem Description Input The input contains a single line consisting of 2 integers N and M (1≤N≤10^18, 2≤M≤100). Output Print one integer, the total n…
God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him that some sequence of eating will make them poisonous. Every hour, God Water will eat one kind of food among meat, fish and chocolate. If there are 3 c…