题目描述 Description

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 号小伙伴最后走到了第几号位置。

输入描述 Input Description

输入共 1 行,包含 4 个整数 n、m、k、x,每两个整数之间用一个空格隔开。

输出描述 Output Description

输出共 1 行,包含 1 个整数,表示 10^k 轮后 x 号小伙伴所在的位置编号。

样例输入 Sample Input

10 3 4 5

样例输出 Sample Output

5

数据范围及提示 Data Size & Hint

对于 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。

//找规律加快速幂
#include<cstdio>
#include<iostream>
#define LL long long
using namespace std;
LL n,m,k,x;
LL poww(LL a,LL b)
{
LL r=,base=a;
while(b)
{
if(b&)r*=base;
base*=base;
base%=n;
b/=;
r%=n;
}
return r%=n;
}
int main()
{
cin>>n>>m>>k>>x;
LL temp=(m*(poww(,k)+n)+x)%n;
cout<<temp;
return ;
}

转圈游戏(codevs 3285)的更多相关文章

  1. 3285 转圈游戏 2013年NOIP全国联赛提高组

    3285 转圈游戏 2013年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond       题目描述 Description n 个小伙伴 ...

  2. codevs3285转圈游戏

    传送门 3285 转圈游戏 2013年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Descript ...

  3. [快速幂][NOIP2012]转圈游戏

    转圈游戏 题目描述 n 个小伙伴(编号从 0 到 n-1)围坐一圈玩游戏.按照顺时针方向给 n 个位置编号,从0 到 n-1.最初,第 0 号小伙伴在第 0 号位置,第 1 号小伙伴在第 1 号位置, ...

  4. 洛谷 P1965 转圈游戏

    洛谷 P1965 转圈游戏 传送门 思路 每一轮第 0 号位置上的小伙伴顺时针走到第 m 号位置,第 1 号位置小伙伴走到第 m+1 号位置,--,依此类推,第n − m号位置上的小伙伴走到第 0 号 ...

  5. 1617:转圈游戏 ybt

    1617:转圈游戏 时间限制: 1000 ms         内存限制: 524288 KB提交数: 540     通过数: 326 [题目描述] nn 个小伙伴(编号从 00 到 n−1n−1 ...

  6. 题解 【NOIP2013】转圈游戏

    [NOIP2013]转圈游戏 Description n个小伙伴(编号从0到n-1)围坐一圈玩游戏.按照顺时针方向给n个位置编号,从0到n-1.最初,第0号小伙伴在第0号位置,第1号小伙伴在第1号位置 ...

  7. luoguP1965 转圈游戏(NOIP2013)(快速幂)

    luogu P1965 转圈游戏 题目 #include<iostream> #include<cstdlib> #include<cstdio> #include ...

  8. 洛谷P1965 转圈游戏 [2013NOIP提高组 D1T1][2017年6月计划 数论04]

    P1965 转圈游戏 题目描述 n 个小伙伴(编号从 0 到 n-1)围坐一圈玩游戏.按照顺时针方向给 n 个位置编号,从0 到 n-1.最初,第 0 号小伙伴在第 0 号位置,第 1 号小伙伴在第 ...

  9. 快速幂——while理解&&[P1965] 转圈游戏

    快速幂--while理解 \[a^k\] 把k转成2进制 \[k=2^n*p[n]+2^(n-1)*p[n-1]+...+2^1*p[1]+2^0*p[0]\] \[a^k=a^(2^n*p[n]+2 ...

随机推荐

  1. STL Iterators

    Summary of Chapter 33 STL Iterators from The C++ Programming Language 4th. Ed., Bjarne Stroustrup. - ...

  2. Activity启动模式 及 Intent Flags 与 栈 的关联分析

     http://blog.csdn.net/vipzjyno1/article/details/25463457    Android启动模式Flags栈Task   目录(?)[+] 什么是栈 栈 ...

  3. easyui 动态修改窗口title

    http://blog.csdn.net/liu251890347/article/details/39292307?utm_source=tuicool 使用easyui作为前台框架极大的节省了项目 ...

  4. PHP中GD2的运用,注意编码格式的改变,以及head()函数之前不能有任何html元素包括空格!!!

    <?php header ( "Content-type: text/html; charset=utf-8" ); //设置文件编码格式 header("Cont ...

  5. The Joys of Conjugate Priors

    The Joys of Conjugate Priors (Warning: this post is a bit technical.) Suppose you are a Bayesian rea ...

  6. Unity3d三大光照渲染介绍

      重要:在目前市面上常见的游戏引擎中,主要采用以下三种灯光实现方式: 顶点照明渲染路径细节 Vertex Lit Rendering Path Details 正向渲染路径细节 Forward Re ...

  7. varnish4.0简介

    Varnish 4.0 简介 Varnish 是一款开源的HTTP加速器和反向代理服务器,它的主要特点有: (1)是基于内存缓存,重启后数据将消失.(2)利用虚拟内存方式,io性能好.(3)支持设置0 ...

  8. apache LogFormat参数说明

    在apache的配置文件httpd.conf里一般都有类似于LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Refere ...

  9. Spring IoC实现解耦合

    public class UserDaoImpl implements UserDao{ @Override public void save(User user) { // TODO Auto-ge ...

  10. linux 访问tomcat 管理页面时 You are not authorized to view this page 403(真实可用)

    ava代码 收藏代码 You are not authorized to view this page. If you have not changed any configuration files ...