-
Notifications
You must be signed in to change notification settings - Fork 0
/
id0056.c
47 lines (36 loc) · 845 Bytes
/
id0056.c
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
// Licensed under the MIT License.
// Powerful Digit Sum
#include <gmp.h>
#include <math.h>
#include "../lib/euler.h"
int main(void)
{
int max = 0;
mpz_t megahuge;
clock_t start = clock();
String str = string(math_length(99, 99));
mpz_init(megahuge);
for (int b = 99; b >= 1; b--)
{
if (max >= 9 * math_length(99, b))
{
break;
}
for (int a = 99; a >= 90; a--)
{
int sum = 0;
mpz_ui_pow_ui(megahuge, a, b);
mpz_get_str(str, 10, megahuge);
for (char* p = str; *p; p++)
{
sum += *p - '0';
}
if (sum > max)
{
max = sum;
}
}
}
mpz_clear(megahuge);
return euler_submit(56, max, start);
}