题目链接:https://ac.nowcoder.com/acm/contest/903/H
解题心得:直接跟着模拟就行了。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int t; scanf("%d", &t);
while(t--) {
ll n, k;
scanf("%lld%lld", &n ,&k);
ll ans = n;
if(k == 2) {
n = n*n;
}
while(ans%10 != ans) {
ll temp = 0;
while(ans) {
temp += ans%10;
ans /= 10;
}
ans = temp;
}
printf("%lld\n", ans);
}
return 0;
}