mirror of
https://github.com/xlucn/PAT.git
synced 2026-02-06 19:12:14 +08:00
21 lines
383 B
C
21 lines
383 B
C
#include <stdio.h>
|
|
|
|
int main()
|
|
{
|
|
int A, B, D, Sum;
|
|
scanf("%d %d %d", &A, &B, &D);
|
|
Sum = A + B;
|
|
|
|
/* calculate the bits of Sum */
|
|
int power = 1;
|
|
/* use Sum / D >= power to avoid using long int */
|
|
while (Sum / D >= power)
|
|
power *= D;
|
|
|
|
/* calculate D-base number. print them on-the-fly */
|
|
for (; power > 0; Sum %= power, power /= D)
|
|
printf("%d", Sum / power);
|
|
|
|
return 0;
|
|
}
|