当前位置:网站首页>Informatics Olympiad all in one 1617: circle game | 1875: [13noip improvement group] circle game | Luogu p1965 [noip2013 improvement group] circle game
Informatics Olympiad all in one 1617: circle game | 1875: [13noip improvement group] circle game | Luogu p1965 [noip2013 improvement group] circle game
2022-07-28 09:18:00 【Jun Yi_ noip】
【 Topic link 】
ybt 1617: Circle game
ybt 1875:【13NOIP Improvement group 】 Circle game
Luogu P1965 [NOIP2013 Improvement group ] Circle game
【 Topic test site 】
1. Modulus operation
【 Their thinking 】
The first x After the first round, little buddy No. 1 went to x + m x+m x+m Location , Come after the second round x + 2 m x+2m x+2m Location , If the value of this position exceeds n, The position number should be reduced n, Make the position number only in 0~n-1 Within the scope of . therefore 1 0 k 10^k 10k After wheel , The first x The location of little partner No. is ( x + 1 0 k ⋅ m ) % n (x+10^k\cdot m)\%n (x+10k⋅m)%n.
It is known that x、m All less than n. According to the multiplication application of congruence theorem : a ⋅ b % m = ( a % m ⋅ b % m ) % m a\cdot b \% m = (a\%m \cdot b\%m)\%m a⋅b%m=(a%m⋅b%m)%m
Yes :
( x + 1 0 k ⋅ m ) % n (x+10^k\cdot m)\%n (x+10k⋅m)%n
= ( x % n + ( 1 0 k % n ⋅ m % n ) % n ) % n =(x\%n+(10^k\%n\cdot m\%n)\%n)\%n =(x%n+(10k%n⋅m%n)%n)%n
= ( x + ( 1 0 k % n ⋅ m ) % n ) % n =(x+(10^k\%n\cdot m)\%n)\%n =(x+(10k%n⋅m)%n)%n
The main problem is to seek 1 0 k % n 10^k\%n 10k%n
k achieve 1 0 9 10^9 109, A fast power algorithm must be used here ( The complexity of fast power algorithm is O ( l o g n ) O(logn) O(logn),n Is the size of the index ).
According to the congruence Theorem , Yes : a b % m = ( a % m ) b a^b\%m = (a\%m)^b ab%m=(a%m)b. In the process of using fast power , For the base number a And result r, After every operation, it's right m Take the mold .
【 Solution code 】
solution 1: Fast power
#include<bits/stdc++.h>
using namespace std;
int fastPowMod(int a, int b, int m)// Fast exponentiation a^b%m
{
int r = 1;// result
while(b > 0)
{
if(b % 2 == 1)
r = (r * a) % m;
a = (a * a) % m;
b /= 2;
}
return r;
}
int main()
{
int n, m, k, x;
cin >> n >> m >> k >> x;
cout << (x + fastPowMod(10, k, n) * m % n) % n;
return 0;
}
边栏推荐
猜你喜欢

从开发转测试:我从零开始,一干就是6年的自动化测试历程

IDC脚本文件运行

2022年危险化学品经营单位安全管理人员上岗证题目及答案

训练一个自己的分类 | 【包教包会,数据都准备好了】

2022年安全员-B证考试模拟100题及答案

AMQ streams (1) of openshift 4 - multiple consumers receive data from partition

Dapp安全总结与典型安全事件分析

蓝牙技术|2025年北京充电桩总规模达70万个,聊聊蓝牙与充电桩的不解之缘

DIY system home page, your personalized needs PRO system to meet!

v-bind指令的详细介绍
随机推荐
01-TensorFlow计算模型(一)——计算图
C#简单调用FMU ,进行仿真计算
【leetcode周赛总结】LeetCode第 83场双周赛(7.23)
关闭页面时向后台发送消息
CakePHP 4.4.3 发布,PHP 快速开发框架
golang 协程的实现原理
ES6 let and Const
力扣题(1)—— 两数之和
侯捷STL标准库和泛型编程
Learn to draw with nature communications -- complex violin drawing
台大林轩田《机器学习基石》习题解答和代码实现 | 【你值得拥有】
Huid learning 7: Hudi and Flink integration
网络层的IP协议
负数的十六进制表示
AMQ streams (1) of openshift 4 - multiple consumers receive data from partition
完善的交叉编译环境记录 peta 生成的shell 脚本
[592. Fraction addition and subtraction]
Data analysis interview question summary
Go waitgroup and defer
The new mode of 3D panoramic display has become the key to breaking the game