AtCoder Regular Contest 106 解题报告

arc106_a 106

AtCoder Regular Contest 106 的第一题,签到。

题目链接:A – 106

题意翻译

  • 给定 \( n ( 1 \leq n \leq 10 ^ { 18 } ) \),求解 \( a , b \in \mathbb{ N _ + } \) 满足 \( 3 ^ a + 5 ^ b = n \),输出任意一组解即可。

题解

枚举答案即可。

#include <bits/stdc++.h>
using namespace std;
#define reg register
typedef long long ll;
#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++)
static char buf[100000], *p1 = buf, *p2 = buf;
inline ll read(void)
{
    reg bool f = false;
    reg char ch = getchar();
    reg ll res = 0;
    while (!isdigit(ch))
        f |= (ch == '-'), ch = getchar();
    while (isdigit(ch))
        res = 10ll * res + ch - '0', ch = getchar();
    return f ? -res : res;
}

int main(void)
{
    reg ll n = read();
    for (reg ll i = 5, j = 1; i <= n; i *= 5, ++j)
    {
        reg ll res = n - i, cnt = 0;
        while (res > 1 && res % 3 == 0)
            res /= 3, ++cnt;
        if (res == 1 && cnt > 0)
        {
            printf("%lld %lld\n", cnt, j);
            return 0;
        }
    }
    puts("-1");
    return 0;
}
Pages: 1 2 3 4 5 6 7 8