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

转圈游戏

时间:2019-08-16 00:42:26      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:can   bsp   水题   ret   div   color   while   class   span   

[Time Gate]

https://www.luogu.org/problem/P1965

【解题思路】

一道遗漏的数论水题

仔细观察不难发现公式:位置编号=(x+10^k*m)%n

那么k这么大,又是求幂,妥妥的快速幂模板!!

【code】

 1 #include <cstdio>
 2 #include <algorithm>
 3 using namespace std;
 4 int n,m,k,x;
 5 long long ans;
 6 inline long long ksm(int a,int b){
 7     ans=1;
 8     while(b){
 9         if(b&1)
10             ans=ans*a%n;
11         a=a*a%n;
12         b>>=1;
13     }
14     return ans;
15 }
16 int main(){
17     scanf("%d%d%d%d",&n,&m,&k,&x);
18     printf("%lld\n",(x%n+ksm(10,k)%n*m)%n);
19     return 0;
20 }

 

转圈游戏

标签:can   bsp   水题   ret   div   color   while   class   span   

原文地址:https://www.cnblogs.com/66dzb/p/11361356.html

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