Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Bitnami MediaWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
0631 - Passwd
(section)
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
= Exemplul 3: = <code>passwdIN.txt</code> 2 1 1 1 2501 66 <code>passwdOUT.txt</code> Datele nu corespund restrictiilor impuse . == Rezolvare == <syntaxhighlight lang="python3" line="1"> MOD = 666013 nmax = 2501 def put(a, b): rez = 1 while b: if b & 1: rez = (rez * a) % MOD a = (a * a) % MOD b >>= 1 return rez def preprocesare(): fact[0] = 1 inv[0] = 1 fact[1] = 1 inv[1] = 1 for i in range(2, nmax * 4): fact[i] = (fact[i - 1] * i) % MOD inv[i] = put(fact[i], MOD - 2) def comb(n, k): if n == k or k == 0: return 1 rez = ((fact[n] * inv[n - k]) % MOD * inv[k]) % MOD return rez def baga(pos, a, b, c, d): global gata, cntPasswd if pos == n + 1: cntPasswd += 1 if cntPasswd == X: gata = True g.write("".join(Sol[1:n + 1]) + "\n") return else: if a: for i in range(97, 123): Sol[pos] = chr(i) baga(pos + 1, a - 1, b, c, d) if gata: return if b: for i in range(65, 91): Sol[pos] = chr(i) baga(pos + 1, a, b - 1, c, d) if gata: return if c: for i in range(48, 58): Sol[pos] = chr(i) baga(pos + 1, a, b, c - 1, d) if gata: return if d: for i in v: Sol[pos] = i baga(pos + 1, a, b, c, d - 1) if gata: return def primaCerinta(): v.extend(['!', '@', '#', '$', '%']) baga(1, a, b, c, d) def a2Cerinta(): preprocesare() rez = (comb(n, a) * put(26, a)) % MOD rez = (rez * comb(n - a, b)) % MOD rez = (rez * put(26, b)) % MOD rez = (rez * comb(n - a - b, c)) % MOD rez = (rez * put(10, c)) % MOD rez = (rez * comb(n - a - b - c, d)) % MOD rez = (rez * put(5, d)) % MOD g.write(f"{rez}\n") def verifica_restrictii(a, b, c, d, X): if not (1 <= a <= 2500 and 1 <= b <= 2500 and 1 <= c <= 2500 and 1 <= d <= 2500 and 1 <= X <= 4000000): with open("passwdOUT.txt", "w") as g: g.write("Datele nu corespund restrictiilor impuse\n") return False return True def rezolva(): global n n = a + b + c + d if tip == 1: primaCerinta() else: a2Cerinta() def main(): global tip, a, b, c, d, X, v, cntPasswd, Sol, gata, fact, inv, n, g with open("passwdIN.txt", "r") as f: tip = int(f.readline().strip()) a, b, c, d = map(int, f.readline().strip().split()) X = int(f.readline().strip()) if not verifica_restrictii(a, b, c, d, X): return v = [] cntPasswd = 0 Sol = [""] * (nmax * 4) gata = False fact = [0] * (nmax * 4) inv = [0] * (nmax * 4) with open("passwdOUT.txt", "w") as g: rezolva() if __name__ == "__main__": main() </syntaxhighlight>
Summary:
Please note that all contributions to Bitnami MediaWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Bitnami MediaWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width