-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
4 yuyu0830 #18
4 yuyu0830 #18
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
νμ΄κ° μ΄λ ΅μ§λ§ bitλ‘λ ν μ μκ΅°μ©...
ν΄λΉ λ¬Έμ λ₯Ό μ²μλ΄€μλ νλ ¬ μ κ³±μΌλ‘λ§ λ²
μ°Όλλ° μκ° μ΄κ³Όλ‘ λΈλ‘κ·Έλ₯Ό μ°Έκ³ ν΄μ μ κ³± μλ΅μ΄ κ°λ₯νλ¨κ±Έ κΉ¨λ¬μμλ μ μ νλ λλμ΄ κΈ°μ΅λλ€μ.
μ λ bκ° νμ μΌλ λ¨μνλ ¬μ μ κ³±μ ν΄μ€λ€ νλ ¬ μ κ³±μΌλ‘ νμ΄λκ°μλλ° μ κΈ°νλ€μ!
} | ||
} | ||
|
||
long long int pointer = 137438953472; // 2^38 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pointer λ³μμ μ ν΄λΉ κ°μ΄ λ€μ΄κ°λμ§ μ μ μμκΉμ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ΅κ³ κ°μ΄ 100,000,000,000 μ΄κ³ , ν΄λΉ κ°λ³΄λ€ λ ν° 2μ μ κ³± μ μ€μ κ°μ₯ μμ μκ° 2^37? 38? μΈ 137,438,953,472 μμ΅λλ€! 1 << 63 ν΄μ μμ μ²μλΆν° λΉκ΅ν΄λ λλλ° μ΄μ°¨νΌ μ΅κ³ κ°μ΄ 100,000,000,000μ΄λκΉ μ‘°κ±΄λ³΄λ€ ν° μ μ€μ κ°μ₯ μμ μμΈ 2^37? 38? μ 골λμ΅λλ€ :)
long long int pointer = 137438953472; // 2^38 | ||
|
||
// bμ λΉκ΅ν μ μλ μμΉλ‘ ν¬μΈν° μΈν | ||
while (!(b & pointer)) pointer = pointer >> 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ΄ λΆλΆλ κΆκΈν©λλ€! μ€λͺ λΆνλ립λλ€.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ΄λ° μμΌλ‘ pointer
μ 1μ© bit shift ν΄λκ°λ©° bμ bit AND μ°μ°μ νλ λ°©λ²μ
λλ€!
κ·Έλ°λ° b
μ κ°μ΄ μ΄μ°¨νΌ μ΅λκ° 100,000,000,000 μ΄κΈ° λλ¬Έμ ν΄λΉ κ°μΈ 2^37? 38? μΈ 137,438,953,472
μ΄ κ°λΆν° μμν©λλ€!
κ·Έλ κ² νλ©΄ 2^37? 38? λΆν° bit shiftλ₯Ό νλ©° bit AND λΉκ΅λ₯Ό ν ν
λ° μ§κΈ λμ€λ 0μ΄ bμ ν¬κΈ° μ μν₯μ΄ μλ 0μΈμ§, μλλ©΄ bλ₯Ό μ΄λ£¨λ 2μ§μμ ν¬ν¨λ 0μΈμ§ μ λ°©λκ° μμ΅λλ€.
κ·Έλμ μ²μ 1μ΄ λμ¬ λ κΉμ§ pointerλ₯Ό >> 1 shiftν΄μ λΉκ²¨μ μ°μ°μ μμν©λλ€
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cn = []
while True:
if b==1:
break
elif b%2==0: # μ§μ
b = b//2
cn.append(1)
else:
b = (b-1)//2
cn.append(0)
t = A
for i in range(len(cn)-1,-1,-1):
if cn[i] == 1:
A = matrixmult(A,A)
else:
C = matrixmult(A,A)
A = matrixmult(t,C)
μμ μ νμλ λ¬Έμ μΈλ° bκ° μ§μμΌ λμ νμμΌ λλ₯Ό λλμ΄μ νμλ κΈ°μ΅μ΄ λλ€μ. λΉνΈλ₯Ό μ΄μ©ν μ°Έμ ν νμ΄ μ λ΄€μ΅λλ€ !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int fac(int b) {
if (b==1) return a % c;
long long int m = fac(b / 2);
if (b % 2 == 0) return m * m % c;
else return (m * m %c * a % c) % c;
}
μ λ μ μ¬ν λΆν μ 볡
κ³±μ
λ¬Έμ λ₯Ό νΌμ μ΄μλλ° μ λ μ§μλΆλΆμ κ³μ 2λ‘ λλ
μ€μ μ¬κ·νΈμΆ
μ ν΅ν λ°©μμΌλ‘ νμλλ° μ΄λ κ² λΉνΈμ°μ°μΌλ‘λ νμμκ΅°μ μ’λ 곡λΆν΄μΌκ² μ΅λλ€,,
π λ¬Έμ λ§ν¬
νλ ¬ μ κ³±
βοΈ μμλ μκ°
30λΆ
β¨ μλ μ½λ
λΈλ‘κ·Έ νμ΄
μ 보보νΈλ‘ μμ μνΈλ₯Ό ꡬνν λ μ¬μ©νλ
Double-and-Add Method
λΌλ λ°©μμ μ¬μ©νμ΅λλ€.μ«μ
n
μb
λ² μ κ³±ν λ,n
μb
λ² μ§μ λ€ κ³±νλ λ°©λ²λ μμ΅λλ€.νμ§λ§ (n*n)^2 μ΄λ κ² μ§κΈ κ³±νκ³ μλ μ μ체λ₯Ό μ κ³±ν΄ μ°μ°μ μ€μΌ μ μμ΅λλ€.
λ°λΌμ κΈ°μ€μ΄ λλ λ°°μ΄
crit
, νμ¬ μλ₯Ό μ μ₯νλ λ°°μ΄arr
λκ°λ₯Ό λμ΄ nμ κ³±ν λλarr
*crit
, μ¦Adding
λ₯Ό νκ³ , μ체λ₯Ό κ³±ν λλarr
*arr
, μ¦Doubling
λ₯Ό μ€νν΄ μ°μ°νμ΅λλ€.Double-and-Add Method
λ 2μ§μκ° μ μΌ μμ bitλ₯Ό μ μΈν λ€, μμμλΆν° 1μ΄λ©΄* 2 + 1
, 0μ΄λ©΄* 2
λ₯Ό μνν΄ ν΄λΉ μλ₯Ό λ§λ€ μ μλ€λ μ μ μ°©μνμ΅λλ€.26μ κ³μ°ν μμ
bit wise μ°μ°μ ν΅ν΄ κ° bitλ³ μλ₯Ό νμΈν΄ Doublingμ Adding μ°μ° μ¬λΆλ₯Ό κ²°μ νμ΅λλ€. μ΄νλ 1000 λλ¨Έμ§ μ°μ°λ§ ν΄μ£Όλ©΄ λ!
π μλ‘κ² μκ²λ λ΄μ©
bit shiftλ ν λ²μ 16 μ΄μ λͺ»ν©λλ€! b λ² μ κ³±ν΄μΌνκ³ ,
b
κ° μ΅λ 100,000,000,000 λΌμ1 << 37
λ‘ μ°λ €κ³ νλλ° μκΎΈ μ€λ₯κ° λ¨λ€μ....