-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbig_integer_modulo_main.c
More file actions
48 lines (44 loc) · 1.72 KB
/
big_integer_modulo_main.c
File metadata and controls
48 lines (44 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
5 kyu
Big Integer Modulo
https://www.codewars.com/kata/546e0773fa8da2013200087a
*/
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
uint64_t big_modulo(const char*, uint64_t);
void do_test(const char* num_string, uint64_t divisor, uint64_t expected) {
uint64_t actual = big_modulo(num_string, divisor);
printf("big_modulo(\"%s\",\n%" PRIu64 ")\nreturned %" PRIu64
",\nexpected %" PRIu64 "\n%s\n\n",
num_string, divisor, actual, expected,
actual == expected ? "OK" : "ERROR");
}
int main(void) {
do_test("1236", 11ULL, 1236 % 11);
do_test("1236", 123456ULL, 1236 % 123456);
do_test("987654321", 1234ULL, 987654321ULL % 1234);
do_test("18446744073709551619", 18446744073709551615ULL, 4ULL);
do_test(
"987654321987654321987654321987654321987654321987654321987654321987654321"
"9876543212",
2ULL, 0ULL);
do_test(
"235711131719232931374143475359616771737983878991972357111317192329313741"
"434753596167717379838789919723571113171923293137414347535961677173798387"
"899197",
1123581321ULL, 1027387815ULL);
do_test(
"235711131719232931374143475359616771737983878991972357111317192329313741"
"434753596167717379838789919723571113171923293137414347535961677173798387"
"899197987654321987654321987654321987654321987654321987654321987654321987"
"6543219876543217",
235711ULL, 178215ULL);
do_test(
"684366450234127464721582832475654380947172706442044214697034599129334141"
"511278482923502307958171026631914334194306868098905714047702023458868218"
"096817808471085758070315223264293994686643843520547799433751380692272066"
"462936090780835",
18446744073709551615ULL, 3793403237254995000ULL);
return 0;
}