mirror of
https://github.com/xlucn/PAT.git
synced 2026-10-03 00:23:15 +08:00
20 lines
415 B
C
20 lines
415 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;
|
|
}
|