Download benchmarks/Algorithms/euler_theorem_inverse/solution.c from PV-SJTU/PV-Bench: direct link, hf CLI and curl.
- Browser
- Download file 858 Bytes
-
https://huggingface.co/datasets/PV-SJTU/PV-Bench/resolve/main/benchmarks/Algorithms/euler_theorem_inverse/solution.c
- Command line
-
hf download hf://datasets/PV-SJTU/PV-Bench/benchmarks/Algorithms/euler_theorem_inverse/solution.c
-
curl -L -o solution.c https://huggingface.co/datasets/PV-SJTU/PV-Bench/resolve/main/benchmarks/Algorithms/euler_theorem_inverse/solution.c
858 Bytes
| int euler_phi(int value) | |
| { | |
| int result = value; | |
| for (int factor = 2; factor * factor <= value; ++factor) { | |
| if (value % factor == 0) { | |
| while (value % factor == 0) { | |
| value /= factor; | |
| } | |
| result = result / factor * (factor - 1); | |
| } | |
| } | |
| if (value != 1) { | |
| result = result / value * (value - 1); | |
| } | |
| return result; | |
| } | |
| int modular_power(int base, int exponent, int modulus) | |
| { | |
| int result = 1; | |
| while (exponent > 0) { | |
| if (exponent % 2 == 1) { | |
| result = result * base % modulus; | |
| } | |
| base = base * base % modulus; | |
| exponent /= 2; | |
| } | |
| return result; | |
| } | |
| int euler_theorem_inverse(int value, int modulus) | |
| { | |
| int exponent = euler_phi(modulus) - 1; | |
| return modular_power(value, exponent, modulus); | |
| } | |