码迷,mamicode.com
首页 > 其他好文 > 详细

转圈游戏

时间:2019-09-22 15:14:58      阅读:87      评论:0      收藏:0      [点我收藏+]

标签:namespace   pre   快速   ios   推出   游戏   main   ret   tle   

题面

这道题不难可以推出(x+m*10^k)%n

根据模运算的的分配率可以得到 (x%n+m%n*10^k%n)%n只需用快速幂求出10^k就可以了

#include<iostream> 
#include<cstdio> 
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<cstring>
using namespace std; 
int n,m,k,x;
int ksm(int a,int b)
{
    int re=1;
    int t=a;
    while(b)
    {
        if(b&1) re=re*t%n; 
        t=t*t%n;
        b>>=1;
    }
    return re;
}
int main()
{
    cin>>n>>m>>k>>x;
    cout<<(x%n+m%n*ksm(10,k)%n)%n;
    return 0;
}

  

转圈游戏

标签:namespace   pre   快速   ios   推出   游戏   main   ret   tle   

原文地址:https://www.cnblogs.com/ainiyuling/p/11567277.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!