Submission
Status:
--------------------
Subtask/Task Score:
0/100
Score: 0
User: pxsit
Problemset: ปฏิทินวันแม่
Language: cpp
Time: 0.005 second
Submitted On: 2026-10-03 19:51:14
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define endll cout << '\n'
#define sp ' '
#define pii pair<int,int>
int32_t main() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
int t;
cin >> t;
while(t--){
int n;
cin >> n;
unordered_map<int,int> mp;
for(int i=0;i<n;i++){
string s;
cin >> s;
int x = 0;
for(char c : s){
x += (c - '0')*(c - '0');
}
for(int j=0;j<200;j++){
int cur = 0, nw = x;
while(nw){
cur += (nw % 10)*(nw % 10);
nw /= 10;
}
x = cur;
}
mp[x]++;
}
ll ans = 0;
for(auto [x,y] : mp){
y--;
ans += (y*y+y)/2;
}
cout << ans << endl;
}
}