luogu1965 转圈游戏
题目大意
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 号小伙伴最后走到了第几号位置。
题解
大胆想,从整体角度考虑,所求\(=(10^k m+x)\mod n\)。用快速幂、快速幂运算即可。
#include <cstdio>
#include <iostream>
using namespace std;
#define ll long long
ll Mult(ll a, ll b, ll p)
{
ll ans = 0;
while(b)
{
if(b & 1)
ans = (ans + a) % p;
a = (a + a) % p;
b >>= 1;
}
return ans;
}
ll Power(ll a, ll n, ll p)
{
ll ans = 1;
while(n)
{
if(n & 1)
ans=Mult(ans, a, p);
a = Mult(a, a, p);
n >>= 1;
}
return ans;
}
int main()
{
ll n, m, k, x;
cin>>n>>m>>k>>x;
cout<<(Mult(Power(10, k, n), m, n) + x) % n<<endl;
return 0;
}
luogu1965 转圈游戏的更多相关文章
- luogu1965 转圈游戏 (快速幂)
求(m*10^k+x)%n即可 #include<cstdio> #include<cstring> #include<algorithm> #define LL ...
- [快速幂][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 个小伙伴 ...
- codevs3285转圈游戏
传送门 3285 转圈游戏 2013年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Descript ...
- 洛谷 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 号小伙伴在第 ...
随机推荐
- maven添加本地jar包的方法
1.将一个本地的jar包随便放在一个放入本地文件夹中 (文件夹位置 和 jar包名称都随意) 例:F:\java\repository\a 文件夹下,名称为:icepdf-core-6.0.jar 2 ...
- X - Vasya and Socks
Problem description Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pai ...
- C#方法的练习
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo ...
- Scala——面向对象和函数式编程语言
Scala Scala是一门运行时基于JVM的编程语言,具备函数式编程和面向对象特点. 基本知识 basics 任意词均可作为符号名,对于关键词,以反引号包裹,避免使用下划线,避免带美元符的名字. 声 ...
- 【Oracle】服务器端监听配置
一.静态监听 创建端口为1521的监听,静态注册,本机ip:192.168.10.2 [oracle@localhost ~]$ vi /u01/app/oracle/product/11.2.0/d ...
- VHDL之concurrent之block
1 Simple BLOCK The simple block represents only a way of partitioning the code. It allows concurrent ...
- JavaScript编程题(一)
使用Javascript脚板输出如图所示的效果页面: 使用document.write()输出水平线 使用循环控制每个水平线的长度 答案:<!doctype html> <html ...
- Spring MVC 中的基于注解的 Controller(转载)
终于来到了基于注解的 Spring MVC 了.之前我们所讲到的 handler,需要根据 url 并通过 HandlerMapping 来映射出相应的 handler 并调用相应的方法 ...
- C# for 遍历 IPagedList
IPagedList<Doc> ss = Doclist.ToPagedList(page, pageSize); ;i<ss.Count;i++) { var yy = ss[i] ...
- 【转载】java文件路径问题及getResource和getClassLoader().getResource的区别
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u012572955/article/details/52880520我们经常在java的io操作中读 ...