当前位置:网站首页>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;
}
边栏推荐
- c# 有符号和无符号字节变量
- Modify virtual machine IP address
- Vs2015 use dumpbin to view the exported function symbols of the library
- 1.5 merge\rebase\revert\stash\branch
- TXT文本文件存储
- Marketing play is changeable, and understanding the rules is the key!
- 看得清比走得快更重要,因为走得对才能走得远
- Linux initializes MySQL with fatal error: could not find my-default.cnf
- TXT text file storage
- 【SwinTransformer源码阅读二】Window Attention和Shifted Window Attention部分
猜你喜欢
随机推荐
Path and attribute labels of picture labels
NPM and yarn use (official website, installation, command line, uploading your own package, detailed explanation of package version number, updating and uninstalling package, viewing all versions, equ
GBase 8a如何使用使用预处理快速插入数据?
Different HR labels
KEGG通路的从属/注释信息如何获取
CSV文件存储
【leetcode周赛总结】LeetCode第 83场双周赛(7.23)
js数组去重,id相同对某值相加合并
VS2015使用dumpbin 查看库的导出函数符号
OpenShift 4 之AMQ Streams(1) - 多个Consumer从Partition接收数据
Send a message to the background when closing the page
Mysql5.7.38 start keepalived in the container
Get started quickly with flask (I) understand the framework flask, project structure and development environment
Magic Bracelet-【群论】【Burnside引理】【矩阵快速幂】
shell 实现harbor v1/v2的备份/恢复/迁移等功能
C language array pointer and pointer array discrimination, analysis of memory leakage
mysql5.7.38容器里启动keepalived
2022高压电工考试模拟100题及模拟考试
Detailed explanation of MSTP protocol for layer 3 switch configuration [Huawei ENSP experiment]
一款入门神器TensorFlowPlayground









