codevs3285转圈游戏
n 个小伙伴(编号从 0 到 n-1)围坐一圈玩游戏。按照顺时针方向给 n 个位置编号,从0 到 n-1。最初,第 0 号小伙伴在第 0 号位置,第 1 号小伙伴在第 1 号位置,……,依此类推。
游戏规则如下:每一轮第 0 号位置上的小伙伴顺时针走到第 m 号位置,第 1 号位置小伙伴走到第 m+1 号位置,……,依此类推,第n - m号位置上的小伙伴走到第 0 号位置,第n-m+1 号位置上的小伙伴走到第 1 号位置,……,第 n-1 号位置上的小伙伴顺时针走到第m-1 号位置。
现在,一共进行了 10^k 轮,请问 x 号小伙伴最后走到了第几号位置。
输入共 1 行,包含 4 个整数 n、m、k、x,每两个整数之间用一个空格隔开。
输出共 1 行,包含 1 个整数,表示 10^k 轮后 x 号小伙伴所在的位置编号。
10 3 4 5
5
对于 30%的数据,0 < k < 7;
对于 80%的数据,0 < k < 10^7;
对于 100%的数据,1 < n < 1,000,000,0 < m < n,1 <= x <=n,0 < k < 10^9。
【思路】快速幂
定义重变量GG
【code】
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int nn,m,k,x;
long long fast_mod(int n,int p)
{
long long now=n,ans=;
while(p)
{
if(p&)
{
ans=ans*now;
ans%=nn;
}
now=now*now;
now%=nn;
p>>=;
}
return ans;
}
int main()
{
scanf("%d%d%d%d",&nn,&m,&k,&x);
printf("%lld",(x+fast_mod(,k)*m)%nn);
return ;
}
codevs3285转圈游戏的更多相关文章
- codevs3285 转圈游戏
题目描述 Description n 个小伙伴(编号从 0 到 n-1)围坐一圈玩游戏.按照顺时针方向给 n 个位置编号,从0 到 n-1.最初,第 0 号小伙伴在第 0 号位置,第 1 号小伙伴在第 ...
- 【基础练习】【高速幂】codevs3285 转圈游戏题解
转载请注明出处 来自CSDN用户ametake 题目来自NOIP2013TGD1T1 题目描写叙述 Description n 个小伙伴(编号从 0 到 n-1)围坐一圈玩游戏.依照顺时针方向给 n ...
- [快速幂][NOIP2012]转圈游戏
转圈游戏 题目描述 n 个小伙伴(编号从 0 到 n-1)围坐一圈玩游戏.按照顺时针方向给 n 个位置编号,从0 到 n-1.最初,第 0 号小伙伴在第 0 号位置,第 1 号小伙伴在第 1 号位置, ...
- 3285 转圈游戏 2013年NOIP全国联赛提高组
3285 转圈游戏 2013年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description n 个小伙伴 ...
- 洛谷 P1965 转圈游戏
洛谷 P1965 转圈游戏 传送门 思路 每一轮第 0 号位置上的小伙伴顺时针走到第 m 号位置,第 1 号位置小伙伴走到第 m+1 号位置,--,依此类推,第n − m号位置上的小伙伴走到第 0 号 ...
- 1617:转圈游戏 ybt
1617:转圈游戏 时间限制: 1000 ms 内存限制: 524288 KB提交数: 540 通过数: 326 [题目描述] nn 个小伙伴(编号从 00 到 n−1n−1 ...
- 题解 【NOIP2013】转圈游戏
[NOIP2013]转圈游戏 Description n个小伙伴(编号从0到n-1)围坐一圈玩游戏.按照顺时针方向给n个位置编号,从0到n-1.最初,第0号小伙伴在第0号位置,第1号小伙伴在第1号位置 ...
- luoguP1965 转圈游戏(NOIP2013)(快速幂)
luogu P1965 转圈游戏 题目 #include<iostream> #include<cstdlib> #include<cstdio> #include ...
- 洛谷P1965 转圈游戏 [2013NOIP提高组 D1T1][2017年6月计划 数论04]
P1965 转圈游戏 题目描述 n 个小伙伴(编号从 0 到 n-1)围坐一圈玩游戏.按照顺时针方向给 n 个位置编号,从0 到 n-1.最初,第 0 号小伙伴在第 0 号位置,第 1 号小伙伴在第 ...
随机推荐
- ROS下使用ASUS Xtion Pro Live
一.ROS官网hydro版本OpenNI安装 3. Installation 3.1 Ubuntu installation To install only openni_camera: sudo a ...
- 数字巨头们的表态--<大佬与大话>
作者魏武挥 类别非虚构 / 中篇 本书为作者为<21世纪商业评论>的专栏文章合集,共20篇,算是第一卷吧,后期还会写下去.这个专栏的名字叫<大佬与大话>,专门收集TMT圈子商业 ...
- Xcode not building app with changes incorporated
Did you clean the build folder by pressing command while the cursor is on the clean option? Are you ...
- R12: How to add Microsoft Excel as Type to the Create Template List of Values in BI Publisher (Doc ID 1343225.1)
Modified: 27-Oct-2013 Type: HOWTO In this Document Goal Solution References APPLIES TO: BI Publisher ...
- ReactNavtive框架教程(3)
原文:http://www.raywenderlich.com/99473/introducing-react-native-building-apps-javascript 注意:全部图片放在了百度 ...
- 单词number 和 numeral 的区别
原文: http://blog.sina.com.cn/s/blog_72cd06360100vn7t.html be of 的用法,相当于表征特征或属性的形容词. 简单地说,“of + 名词”等于“ ...
- ivy 入门
ivy 入门 http://www.blogjava.net/aoxj/archive/2009/03/31/263012.html https://www.cnblogs.com/end/archi ...
- nginx配置初步
nginx配置初步 1,切换至nginx目录,找到配置文件目录 cd /etc/nginx/conf.d 2,拷贝一份conf文件 sudo cp default.conf head.conf 3,进 ...
- HTML网页之进入站点口令脚本
加入以下这个脚本在head标签中. <script language="JavaScript"> <!-- var password=""; ...
- 哈理工2015 暑假训练赛 zoj 2976 Light Bulbs
MS Memory Limit:65536KB 64bit IO Format:%lld & %llu SubmitStatusid=14946">Practice ...