{"id":19469528,"url":"https://github.com/hackerkid/toolbox","last_synced_at":"2026-03-02T12:34:01.639Z","repository":{"id":71211769,"uuid":"44905873","full_name":"hackerkid/ToolBox","owner":"hackerkid","description":"Collection of useful tools and tricks for competitive programming","archived":false,"fork":false,"pushed_at":"2015-10-25T10:52:49.000Z","size":204,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-08T05:05:17.553Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hackerkid.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}},"created_at":"2015-10-25T10:44:45.000Z","updated_at":"2015-10-25T10:44:45.000Z","dependencies_parsed_at":"2023-03-11T10:04:24.443Z","dependency_job_id":null,"html_url":"https://github.com/hackerkid/ToolBox","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackerkid%2FToolBox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackerkid%2FToolBox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackerkid%2FToolBox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackerkid%2FToolBox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hackerkid","download_url":"https://codeload.github.com/hackerkid/ToolBox/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240683419,"owners_count":19840699,"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-11-10T18:51:44.156Z","updated_at":"2026-03-02T12:33:56.117Z","avatar_url":"https://github.com/hackerkid.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# ToolBox\nCollection of useful tools and tricks for competitive programming\n\n##Modular Exponentiation\n\n```c++\nint modPow(long long b, long long e, int m) {\n    long long res = 1;\n    for (; e; e \u003e\u003e= 1, b = b*b%m) if (e \u0026 1) res = res*b%m;\n    return res;\n}\n````\n\n##Modular Multiplicative Inverse\n\n\n```c++\nvoid extEuclid(int a, int b, int \u0026x, int \u0026y, int \u0026gcd) {\n    x = 0; y = 1; gcd = b;\n    int m, n, q, r;\n      for (int u=1, v=0; a != 0; gcd=a, a=r) {\n          q = gcd / a; r = gcd % a;\n          m = x-u*q; n = y-v*q;\n          x=u; y=v; u=m; v=n;\n      }\n}\n\n    // The result could be negative, if it's required to be positive, then add \"m\"\nint modInv(int n, int m) {\n    int x, y, gcd;\n    extEuclid(n, m, x, y, gcd);\n    if (gcd == 1) return x % m;\n    return 0;\n}\n\n```\n\n###Example\n```\nAnswer = SumDiv( 36^30 ) % MOD                      // Where MOD = 1,000,000,007\n\nA = SumDiv( (2^2 * 3^2) ^ 30 ) % MOD                // Prime factorization of 36\nA = SumDiv( 2^60 * 3^60 ) % MOD                     // Exponent rule\nA = ( (2^61 - 1) / 1 ) * ( (3^61 - 1) / 2 ) % MOD   // Sum of divisors\n\n// At this point, using modular arithmetic brings us to the answer\n\nA = ( ( (2^61 - 1) / 1 ) % MOD ) *  ( ( (3^61 - 1) / 2 ) % MOD ) % MOD\n\nA =   ( (2^61 - 1) % MOD ) * ( 1^-1 ) % MOD\n    * ( (3^61 - 1) % MOD ) * ( 2^-1 ) % MOD\n    % MOD\n    \n// Where x^-1 is the MMI of x, modulo MOD\n\nA =   ( ( modPow(2, 61, MOD) - 1 ) % MOD * modInv(1, MOD) ) % MOD\n    * ( ( modPow(3, 61, MOD) - 1 ) % MOD * modInv(2, MOD) ) % MOD\n    % MOD\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhackerkid%2Ftoolbox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhackerkid%2Ftoolbox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhackerkid%2Ftoolbox/lists"}