{"id":22432129,"url":"https://github.com/normalhuman01/codeforces","last_synced_at":"2025-03-27T07:41:30.169Z","repository":{"id":213779526,"uuid":"734914851","full_name":"normalhuman01/Codeforces","owner":"normalhuman01","description":"Challenges on Codeforces that were within my ability to solve","archived":false,"fork":false,"pushed_at":"2023-12-23T02:29:49.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-01T12:45:26.558Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/normalhuman01.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-12-23T02:24:07.000Z","updated_at":"2023-12-23T02:29:52.000Z","dependencies_parsed_at":"2023-12-23T03:22:04.340Z","dependency_job_id":"2996500d-b470-459c-a501-49dd2d75a2d5","html_url":"https://github.com/normalhuman01/Codeforces","commit_stats":null,"previous_names":["normalhuman01/codeforces"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/normalhuman01%2FCodeforces","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/normalhuman01%2FCodeforces/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/normalhuman01%2FCodeforces/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/normalhuman01%2FCodeforces/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/normalhuman01","download_url":"https://codeload.github.com/normalhuman01/Codeforces/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245805992,"owners_count":20675291,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-05T22:10:41.371Z","updated_at":"2025-03-27T07:41:30.147Z","avatar_url":"https://github.com/normalhuman01.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Codeforces\nCodeforces problems that I could solve :,'v\n\n\n## 628A: Tennis Tournament\n\nThis problem is stated \u003ca href=\"http://codeforces.com/contest/628/problem/A\"\u003ehere\u003c/a\u003e.\n\u003cbr\u003e\n### Solution\nThe solution consists basically in the simulation of the events and counting. First of all, each match would require to spend *2b+1* bottles, because there are *b* bottles for each of the players and one for the judge. Also, the number of matches that will be played in a determined round is 2\u003csup\u003e(\u0026lfloor;logn\u0026rfloor;-1)\u003c/sup\u003e, and the rest of the competitors pass directly to the next round. Finally, the number of towels used are just *np*, because each player receives *p* towels for the whole tournament.\n\u003cbr\u003e\nSince we want 2\u003csup\u003e(\u0026lfloor;logn\u0026rfloor;-1)\u003c/sup\u003e for each *n*, that is the **Most Significant Bit** of *n*, which is easy to compute for numbers that fix into a 32-bit integer. The simulation should stop when the number of players is 1 and we should set a counter for the matches. The answers will be *counter.match* and *np*. The function msb(n) computes the value of highest the power of 2 that is not greater that n.\n\n\u003cpre\u003eAlgorithm\u003c/pre\u003e\n\u003cbr\u003e\n\u003cpre\u003e\nmatch = 2*b+1\ntowels = np\ncounter = 0\nwhile(\u003cem\u003en != 1\u003c/em\u003e)\n  counter += msb(n)/2\n  n = (msb(n))/2 + n - msb(n)\nPrint counter*match,\" \",towels\nEnd\n\u003c/pre\u003e\n\n## 630A: Again Twenty Five!\nThis problem is stated \u003ca href=\"http://codeforces.com/contest/630/problem/A\"\u003ehere\u003c/a\u003e.\n\u003cbr\u003e\n### Solution\nThe solution consists basically in printing the last 2 numbers of 5\u003csup\u003en\u003c/sup\u003e with n\u0026gt;2. We should proove by induction that the answer is always 25.\n\u003col\u003e\n\u003cli\u003e 5\u003csup\u003e2\u003c/sup\u003e = 25. Nothing to proof.\u003c/li\u003e\n\u003cli\u003e Assume that 5\u003csup\u003en\u003c/sup\u003e mod 100 = 25. Inductive Hypothesis.\u003c/li\u003e\n\u003cli\u003e We know that 5\u003csup\u003en\u003c/sup\u003e = 100k + 25, then 5.5\u003csup\u003en\u003c/sup\u003e = 5(100k+25) = 500k+125 = 100(5k+1) + 25, so 5\u003csup\u003e(n+1)\u003c/sup\u003e mod 100 = 25.\u003c/li\u003e\n\u003c/ol\u003e\n\u003cbr\u003e\n\u003cpre\u003eAlgorithm\u003c/pre\u003e\n\u003cbr\u003e\n\u003cpre\u003e\nPrint 25\nEnd\n\u003c/pre\u003e\n\n## 630B: Moore's Law\nThis problem is stated \u003ca href=\"http://codeforces.com/contest/630/problem/B\"\u003ehere\u003c/a\u003e.\n\u003cbr\u003e\n### Solution\nThe solution consists basically in computing the value of f(t), with \n\u003cul\u003e\n\u003cli\u003ef(0) = n.\u003c/li\u003e\n\u003cli\u003ef(t) = 1.000000011.f(t-1), t\u0026gt;0. \u003c/li\u003e\n\u003c/ul\u003e\n\nIt's simple to verify that f(t) = 1.000000011\u003csup\u003et\u003c/sup\u003e.n, so we need to compute this value in less than *O(t)*, because *t* is at most 2.10\u003csup\u003e9\u003c/sup\u003e. Fortunately, there exists the fast exponentiation algorithm, which computes the value of a\u003csup\u003eb\u003c/sup\u003e in *O(log(b))*. Besides that, there's nothing else to explain.\n\u003cbr\u003e\n\u003cpre\u003eFast Exponentiation Algorithm\u003c/pre\u003e\n\u003cbr\u003e\n\u003cpre\u003e\nexpfast(x,n)\n  ans = 1\n  while(\u003cem\u003en\u003c/em\u003e)\n    if(\u003cem\u003e\u0026amp;1\u003c/em\u003e)\n      ans = ans*x\n      n = n-1\n    else\n      a = a*a\n      n = n/2 // We could use n = n\u003e\u003e1\n  return ans\n\u003c/pre\u003e\n\u003cbr\u003e\n\u003cpre\u003eAlgorithm\u003c/pre\u003e\n\u003cbr\u003e\n\u003cpre\u003e\nPrint expfast(1.000000011,t)*n with at least 6 decimals\nEnd\n\u003c/pre\u003e\n\n## 630C: Lucky Numbers\nThis problem is stated \u003ca href=\"http://codeforces.com/contest/630/problem/C\"\u003ehere\u003c/a\u003e.\n\u003cbr\u003e\n### Solution\nThis solution consists basically in counting the quantity of posible numbers exist with no more than *n* digits and formed by only 7's and 8's. Considering that we only have 2 posibilities per digit, then the quantity of numbers with *l* digits woudl be 2\u003csup\u003el\u003c/sup\u003e. Since we want **all** the quantities from numbers with digits from *1* to *n*, then we should compute \u0026sum;q(i) with i \u0026in; [1,n].\n\u003cbr\u003e\nTherefore, the answer for each *n* is: 2\u003csup\u003e1\u003c/sup\u003e + 2\u003csup\u003e2\u003c/sup\u003e+...+2\u003csup\u003en\u003c/sup\u003e. We should know that the sum from 2\u003csup\u003e0\u003c/sup\u003e to 2\u003csup\u003en\u003c/sup\u003e is 2\u003csup\u003e(n+1)\u003c/sup\u003e - 1, then 2\u003csup\u003e1\u003c/sup\u003e + 2\u003csup\u003e2\u003c/sup\u003e+...+2\u003csup\u003en\u003c/sup\u003e = 2\u003csup\u003e(n+1)\u003c/sup\u003e - 1 - 2\u003csup\u003e0\u003c/sup\u003e = 2\u003csup\u003e(n+1)\u003c/sup\u003e - 2.\n\u003cbr\u003e\nA fast way to compute this (it's not really necessary for this problem, though) is **bit shifting**, so we will shift a number *1* *n+1* times and then substract 2. Remember that the maximum number of direct shifts in C++ is 31 because is suported for 32-bit integers. In order to prevent overflow, we should store the answer into a **long long**.\n\u003cbr\u003e\n\u003cpre\u003eAlgorithm\u003c/pre\u003e\n\u003cbr\u003e\n\u003cpre\u003e\nq = 1\nIf \u003cem\u003en\u0026lt;32\u003c/em\u003e\n  Print 1\u0026lt;\u0026lt;(n+1) - 2\nElse\n  q = q\u0026lt;\u0026lt;31\n  n = n - 31\n  Print 1\u0026lt;\u0026lt;(n+1) - 2\nEnd\n\u003c/pre\u003e\n\n## 630J: Divisibility\nThis problem is stated \u003ca href=\"http://codeforces.com/contest/630/problem/J\"\u003ehere\u003c/a\u003e.\n\u003cbr\u003e\n### Solution\nThe solution consists basically in counting the quantity of numbers that are between *1* and *n* that are divisible by 2,3,4,5,6,7,8,9,10. It's very simple to show that the answer is just *n/mcm(2,3,4,5,6,7,8,9,10)*. We can compute previously that mcm(2,3,4,5,6,7,8,9,10) = 2520, so we just return n/2520.\n\u003cbr\u003e\n\u003cpre\u003eAlgorithm\u003c/pre\u003e\n\u003cbr\u003e\n\u003cpre\u003e\nPrint n/2520\nEnd\n\u003c/pre\u003e\n\n\n## 633A: Ebony and Ivory\n\nThis problem is stated \u003ca href=\"https://codeforces.com/contest/633/problem/A\"\u003ehere\u003c/a\u003e.\n\u003cbr\u003e\n### Solution\nThe solution consists basically in verifying wheter the equation *`ak+bt=c`* has at least a non-negative solution for *`(k,t)`*. As this is a diophantine equations, it has infinite integer solutions if and only if *gcd(a,b)|c* (*c mod gcd(a,b) = 0*). Therefore, we should start checking this condition before moving to the actual answer.\n\u003cbr\u003e\nIf the *gcd(a,b)* does divide *c*, considering that *`c \u003c 10001`* and that *`a \u003e 0`*, then the value of *`-1 \u003c c-ak \u003c 10001`*, so we can iterate through *k* and it will do at most *c/a+1* operations (10001 operations max). For each iteration we should check if the remaining from the substraction is a multiple of *b*.\n\u003cbr\u003e\n\u003cpre\u003eAlgorithm\u003c/pre\u003e\n\u003cbr\u003e\n\u003cpre\u003e\nIf \u003cem\u003ec mod gcd(a,b) = 0\u003c/em\u003e\n  For \u003cem\u003ek=0\u003c/em\u003e to \u003cem\u003ek=c/a\u003c/em\u003e\n    If \u003cem\u003e(c-ak) mod b = 0\u003c/em\u003e\n      Print \u003cem\u003e\"Yes\"\u003c/em\u003e\n      End\n  Print \"No\"\nElse\n  Print \"No\"\nEnd\n\u003c/pre\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnormalhuman01%2Fcodeforces","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnormalhuman01%2Fcodeforces","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnormalhuman01%2Fcodeforces/lists"}