c/c++语言开发共享洛谷 P1965 转圈游戏

[TOC] 题目 “P1965 转圈游戏” 思路 数论。题目就是让你判断一下第$x$个人走了$m times 10^k$步之后到了哪里。总共走的步数为$m times 10^k$直接走肯定会 ,对$n$取模之后再走就好了。 $Code$ cpp include include include i …

目录

  • $code$


题目

p1965 转圈游戏

思路

数论。题目就是让你判断一下第$x$个人走了$m times 10^k$步之后到了哪里。总共走的步数为$m times 10^k$直接走肯定会tle,对$n$取模之后再走就好了。

$code$

#include<iostream> #include<cstring> #include<string> #include<cstdio> #include<algorithm> #define int long long using namespace std; int n,m,k,x; int qpow(int a,int b,int mod){     int ans=1,base=a;     while(b){         if(b&1) ans=ans*base%mod;         base=base*base%mod;         b>>=1;     }     return ans; } inline void read(int &t){     int x=0;bool f=0;char c=getchar();     while(c<'0'||c>'9'){if(c=='-')f=!f;c=getchar();}     while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}     t=f?-x:x; }  signed main(){     read(n),read(m);     read(k),read(x);     m%=n;     int qwq=qpow(10,k,n);     int ans=m*qwq%n;     while(ans--){         x++;         if(x==n) x=0;     }     cout<<x<<endl;     return 0; }

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/c-cdevelopment/601963.html

(0)
上一篇 2021年5月11日
下一篇 2021年5月11日

精彩推荐