当前位置:网站首页>2022-02-11 daily clock in: problem fine brush
2022-02-11 daily clock in: problem fine brush
2022-07-03 04:53:00 【Can__ er】
2022-02-11 Clock in every day : Problem fine brush
Write it at the front
“ After these things are skilled , Maybe it's as plain as drinking water , But it can bring great happiness to beginners , I always thought , Can you always keep your enthusiasm as a beginner 、 focus , Determines how far you can go when you do something , How good can you do .” This series of articles is written by python To write , There are three sources of topics : Not done before ;Leetcode secondary , Difficult and difficult questions ; Week title ; The classic topic of a topic , All codes have been AC. everyday 1-3 Avenue , Random analysis , I hope rain or shine , As a record of encouraging yourself to brush questions .
Prison break
Relatively simple , Just recite the fast power .
mod = 100003
m, n = [int(i) for i in input().split(" ")]
ans = pow(m,n,mod)- m*pow(m-1,n-1,mod)
print(ans%mod)
Source code is as follows :
def pow_mod(x, y, z):
"Calculate (x ** y) % z efficiently."
number = 1
while y:
if y & 1:
number = number * x % z
y >>= 1
x = x * x % z
return number
Congruence clue
Here are a few ideas :
- Inverse element : Inverse element is a concept in modular operation , We usually say a yes 【b model c】 Inverse element , In fact, it means a * b = 1 mod c
- Extended Euclidean method : take a ∗ b = 1 m o d c a*b = 1 \mod c a∗b=1modc Turn into a ∗ b − c ∗ some individual whole Count = 1 a*b - c* Some integer = 1 a∗b−c∗ some individual whole Count =1. At this time, by asking exgcd(b, c)—> Use Euclidean algorithm to recurse until x=1,y=0 —> Reverse recursion to find the first layer x and y,x That is to say e model m Inverse element .
from math import *
def exgcd(a, b):
if(b == 0):
return 1,0
# x It's back y,y yes y-x*(a//b)
y, x = exgcd(b, a%b)
y = y - x * (a // b)
return x, y
a, b = map(int, input().split(' '))
x, y = exgcd(a, b)
x = (x + b) % b
print(x)
Add :
边栏推荐
- Triangular rasterization
- 2022 a special equipment related management (elevator) analysis and a special equipment related management (elevator) simulation test
- Notes | numpy-08 Advanced index
- MC Layer Target
- JVM原理简介
- JDBC database operation
- Market status and development prospect prediction of the global fire extinguisher industry in 2022
- Concurrent operation memory interaction
- data2vec! New milestone of unified mode
- Leetcode simple question: check whether the string is an array prefix
猜你喜欢
2022 P cylinder filling test content and P cylinder filling simulation test questions
Leetcode simple question: the key with the longest key duration
Oracle SQL table data loss
Youdao cloud notes
Thesis reading_ Chinese NLP_ ELECTRA
2022 registration of G2 utility boiler stoker examination and G2 utility boiler stoker reexamination examination
Review the configuration of vscode to develop golang
[PCL self study: filtering] introduction and use of various filters in PCL (continuously updated)
String matching: find a substring in a string
Retirement plan fails, 64 year old programmer starts work again
随机推荐
Introduction to JVM principle
The reason why the entity class in the database is changed into hump naming
2022 tea master (intermediate) examination questions and tea master (intermediate) examination skills
Learn to use the idea breakpoint debugging tool
Cross platform plug-in flutter for displaying local notifications_ local_ notifications
Problems encountered in fuzzy query of SQL statements
STM32 reverse entry
Crazy scientist
[XSS bypass - protection strategy] understand the protection strategy and better bypass
M1 Pro install redis
Number of 1 in binary (simple difficulty)
[set theory] relational representation (relational matrix | examples of relational matrix | properties of relational matrix | operations of relational matrix | relational graph | examples of relationa
2022 P cylinder filling test content and P cylinder filling simulation test questions
论文阅读_中文医疗模型_ eHealth
Prepare for 2022 and welcome the "golden three silver four". The "summary of Android intermediate and advanced interview questions in 2022" is fresh, so that your big factory interview can go smoothly
Market status and development prospect prediction of the global fire alarm sensor industry in 2022
第十九届浙江省 I. Barbecue
《牛客刷verilog》Part II Verilog进阶挑战
On typescript and grammar
Interface frequency limit access