当前位置:网站首页>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;
}
边栏推荐
- 蓝牙技术|2025年北京充电桩总规模达70万个,聊聊蓝牙与充电桩的不解之缘
- JSON 文件存储
- Introduction to official account
- Marketing play is changeable, and understanding the rules is the key!
- Train your own classification [Bao Jiaobao, the data are ready]
- Design for failure常见的12种设计思想
- 网络层的IP协议
- MDM data quality application description
- 台大林轩田《机器学习基石》习题解答和代码实现 | 【你值得拥有】
- 公众号简介
猜你喜欢

【高数】高数平面立体几何

TXT text file storage

Hyperlink label

IP protocol of network layer
![[English postgraduate entrance examination vocabulary training camp] day 15 - analyze, general, avoid, surveillance, compared](/img/a8/2c2fab613035f5e50524056d5f51a3.png)
[English postgraduate entrance examination vocabulary training camp] day 15 - analyze, general, avoid, surveillance, compared

The cooperation between starfish OS and metabell is just the beginning

Machine learning: self paced and fine tuning

Sentinel

C language array pointer and pointer array discrimination, analysis of memory leakage

Go interface Foundation
随机推荐
Recommend an artifact to get rid of the entanglement of variable names and a method to modify file names in batches
ES6 let and Const
Review the past and know the new MySQL isolation level
关闭页面时向后台发送消息
负数的十六进制表示
侯捷STL标准库和泛型编程
MDM数据质量应用说明
剑指offer
golang 协程的实现原理
Deconstruction assignment of ES6 variables
Kubernetes data persistence scheme
VR panoramic shooting helps promote the diversity of B & B
Openshift 4 - use verticalpodautoscaler to optimize application resource request and limit
站在大佬的肩膀上,你可以看的更远
mysql5.7.38容器里启动keepalived
Map of China province > City > level > District > Town > village 5-level linkage download [2019 and 2021]
MySQL 8.0.30 GA
Setting of parameter configuration tool for wireless vibrating wire collector
IntelliJ IDEA 关联数据库
2022年安全员-B证考试模拟100题及答案