转圈游戏(luogu 1965)
生活随笔
收集整理的這篇文章主要介紹了
转圈游戏(luogu 1965)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
轉圈游戲
luogu 1965
題目大意
求(x+m×10k)%n(x + m\times 10^k)\%n(x+m×10k)%n
輸入樣例
10 3 4·5輸出樣例
5數據范圍
1<n<10000000<m<n,1?x?n,0<k<1091<n<10000000<m<n,1\leqslant x\leqslant n,0<k<10^91<n<10000000<m<n,1?x?n,0<k<109
解題思路
快速冪計算10k10^k10k,然后直接計算即可
代碼
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define ll long long #define wyc n using namespace std; ll n, m, k, x; ll Counting(ll x, ll y) {ll g = 1;while(y){if (y & 1) g = g * x % wyc;x = x * x % wyc;y >>= 1;}return g; } int main() {scanf("%lld%lld%lld%lld", &n, &m, &k, &x);k = Counting(10ll, k);x = (x + m * k % wyc) % wyc;printf("%lld", x);return 0; }總結
以上是生活随笔為你收集整理的转圈游戏(luogu 1965)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【数学】拉格朗日插值(luogu 478
- 下一篇: 【DP】字串距离(luogu 1279)