QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#177449#6138. Function and FunctionTJ_AndevikingAC ✓25ms3464kbC++201.2kb2023-09-12 23:24:482023-09-12 23:24:49

Judging History

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

  • [2023-09-12 23:24:49]
  • 评测
  • 测评结果:AC
  • 用时:25ms
  • 内存:3464kb
  • [2023-09-12 23:24:48]
  • 提交

answer

#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128_t int128;
typedef pair<int, int> pii;
#define iofast ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define lowbit(x) (x&(-x))
#define inv(x) qpow(x,mod-2)
#define debug(x) cout << (#x) << " = " << x << endl
#define range(x) (x).begin(), (x).end()

const int iINF = 0x3f3f3f3f;
const ll llINF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 998244353;

/*---------------------------------------*/
int cal(const string& s)
{
    int ans = 0;
    for (const auto& c : s) {
        if (c == '0' || c == '4' || c == '6' || c == '9')
            ans += 1;
        else if (c == '8')
            ans += 2;
    }

    return ans;
}
void solve()
{
    int x, k;
    cin >> x >> k;
    if (k == 0) {
        cout << x << '\n';
        return;
    }
    string s = to_string(x);

    int ans;
    do {
        ans = cal(s);
        s = to_string(ans);
        k--;
    } while (k && ans);

    cout << (ans ^ (k & 1)) << '\n';
}

/*---------------------------------------*/

int main()
{
    iofast;
    int t = 1;
    cin >> t;
    while (t--)
        solve();

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3464kb

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: 25ms
memory: 3412kb

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