QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#398773#6138. Function and FunctionSunlightZero#AC ✓16ms3696kbC++14710b2024-04-25 18:05:012024-04-25 18:05:02

Judging History

你现在查看的是最新测评结果

  • [2024-04-25 18:05:02]
  • 评测
  • 测评结果:AC
  • 用时:16ms
  • 内存:3696kb
  • [2024-04-25 18:05:01]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

i64 n, m;
i64 d[10];

i64 get(i64 x)
{
    i64 res = 0;
    while (x)
    {
        res += d[x % 10];
        x /= 10;
    }
    return res;
}

void solve()
{
    cin >> n >> m;

    i64 res = n;
    while (m && res)
    {
        res = get(res);
        m--;
    }
    if (res == 0 && m % 2)
        res = 1;
    cout << res << '\n';
}

void init()
{
    d[0] = d[4] = d[6] = d[9] = 1;
    d[8] = 2;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    init();
    i64 T = 1;
    cin >> T;
    while (T--)
        solve();

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3632kb

input:

6
123456789 1
888888888 1
888888888 2
888888888 999999999
98640 12345
1000000000 0

output:

5
18
2
0
0
1000000000

result:

ok 6 numbers

Test #2:

score: 0
Accepted
time: 16ms
memory: 3696kb

input:

100000
579268184 2
120252252 777743676
255650198 1
152055433 207664522
137430584 754115403
646417467 164848484
743551976 0
0 408695577
363072674 569574204
464290891 0
761830281 3
0 1
49176280 2
791182580 0
474930784 3
402374924 0
739903247 91553857
0 2
688106229 2
65907033 152261569
875191599 3
5319...

output:

0
0
5
0
1
1
743551976
1
1
464290891
0
1
1
791182580
1
402374924
0
0
2
0
1
1
2
1
0
0
0
3
0
0
0
1
0
0
1
0
2
0
1
1
1
0
1
0
0
0
0
0
0
1
55349255
486354015
1
1
0
1
1
0
1
1
0
1
0
9
0
1
1
0
0
1
0
1
1
1
0
0
0
0
25600152
0
0
1
22903397
705086250
771453912
1
1
0
0
1
0
1
1
1
2
1
1
1
1
1
1
6
3
3
1
0
1
0
1
86248...

result:

ok 100000 numbers