Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
820 B
3
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 a,b,x,y;
	scanf("%lu %lu", &a, &b);
	x=base3to10(a);
	y=base3to10(b);

	if (b<a){
		printf("!2\n");
	}

	else if (x*(y-x)>59048){
		printf("!3\n");
	}

	else if (x*(y-x)+y>59048){
		printf("!1\n");
	}

	else {
		printf("%lu\n",base10to3 (x*(y-x)+y));
	}

    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