A. Secrets



http://codeforces.com/problemset/problem/333/A



time limit per test



memory limit per test



input



output


n

One day an unlucky buyer came. He did not have the desired sum without change. Then he took out all his coins and tried to give Gerald a larger than necessary sum with as few coins as possible. What is the maximum number of coins he could get?

The formal explanation of the previous paragraph: we consider all the possible combinations of coins for which the buyer can not give Gerald the sum of n marks without change. For each such combination calculate the minimum number of coins that can bring the buyer at least n


Input



n (1 ≤ n ≤ 1017).

%lld specifier to read or write 64 bit integers in С++. It is preferred to use the cin, cout streams or the %I64dspecifier.


Output



In a single line print an integer: the maximum number of coins the unlucky buyer could have paid with.


Sample test(s)



input



1



output



1



input



4



output



2



题目是这个意思:

让面额总数大于n而又最接近n,且所用硬币总数还最多。

首先1分不能用,假设可以用,则有1+x>n,所以x>=n,如果x=n,则不符合题意,所以x>n,这说明x就能满足要求,所以1分是不能用的。

同理可以证明,当n=3k时,3分是不能用的;当n=9k时,9分是不能用的;……

所以判断n最多是3的多少次方的倍数就行。


完整代码:

/*30ms,0KB*/

#include<cstdio>

int main(void)
{
	__int64 n, deno = 3; //denomination
	scanf("%I64d", &n);
	for (; n % deno == 0; deno *= 3)
		;
	printf("%I64d", n / deno + 1);
	return 0;
}