Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
730 B
4
Indexable
Never
#include <stdio.h>
#include <stdlib.h>

unsigned long int base3to10 (unsigned long int);

unsigned long int base10to3 (unsigned long int);

int main(int argc, char *argv[])
{
    unsigned long int a3, a10;
	scanf("%lu", &a3);
	scanf("%lu", &a10);

	printf("%lu\n", base3to10 (a3));

	if (a10>59048){
		printf("!\n");
	}

	else {
		printf("%lu\n", base10to3 (a10));
	}

    return 0;
}

unsigned long int base3to10 (unsigned long int a){
	unsigned long int b=0, k=1;
	while (a){
		b += k*(a%10);
		k*=3;
		a/=10;
	}

	return b;

}

unsigned long int base10to3 (unsigned long int a){
	unsigned long int b = 0, k = 3, i=1;
	while (a){
		b += (a%k)*i;
		i*=10;
		a/=3;
	}

	return b;

}
Leave a Comment