#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pf push_front
#define in insert
#define f first
#define s second
#define pii pair<int, int>
#define pib pair<int, bool>
#define cint const int
#define mn2 262144
#define nw '\n'
#define sp " "
#define mn 1009
#define inf 400009
#define ms 25000009
#define int long long
using namespace std;
ull ile[11];
ull n;
int t;
pair<ull, int> tab[mn];
vector<int> v;
unordered_map<string, string> mp;
string prt[mn];
string count(const string& si){
if (!mp[si].empty()) return mp[si];
int licz=1;
if(si.size()==1){ mp[si]=si; return si; }
for(int i=0; i<si.size(); ++i) licz*=(si[i]-'0');
string ti=to_string(licz);
string res=count(ti);
//string xd=;
mp[si]=res;
return res;
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>t;
for(int i=0; i<t; ++i){ cin>>tab[i].f; tab[i].s=i; }
sort(tab, tab+t);
n=tab[t-1].f;
int idx=0;
string xd, wyn;
for(ull j=1; j<=n; ++j){
xd=to_string(j);
if (!mp[xd].empty()) wyn=mp[xd];
else wyn=count(xd);
//int cyf=stoi(wyn);
++ile[wyn[0]-'0'];
if(j==tab[idx].f){
for(int i=0; i<=9; ++i){
prt[tab[idx].s]+=to_string(ile[i]);
prt[tab[idx].s]+=" ";
//cout<<ile[i]<<" ";
}
//cout<<nw;
++idx;
}
//cout<<i<<": "<<wyn<<nw;
}
for(int i=0; i<t; ++i){
cout<<prt[i]<<nw;
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | #include <bits/stdc++.h> #define ull unsigned long long #define ll long long #define pb push_back #define pf push_front #define in insert #define f first #define s second #define pii pair<int, int> #define pib pair<int, bool> #define cint const int #define mn2 262144 #define nw '\n' #define sp " " #define mn 1009 #define inf 400009 #define ms 25000009 #define int long long using namespace std; ull ile[11]; ull n; int t; pair<ull, int> tab[mn]; vector<int> v; unordered_map<string, string> mp; string prt[mn]; string count(const string& si){ if (!mp[si].empty()) return mp[si]; int licz=1; if(si.size()==1){ mp[si]=si; return si; } for(int i=0; i<si.size(); ++i) licz*=(si[i]-'0'); string ti=to_string(licz); string res=count(ti); //string xd=; mp[si]=res; return res; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>t; for(int i=0; i<t; ++i){ cin>>tab[i].f; tab[i].s=i; } sort(tab, tab+t); n=tab[t-1].f; int idx=0; string xd, wyn; for(ull j=1; j<=n; ++j){ xd=to_string(j); if (!mp[xd].empty()) wyn=mp[xd]; else wyn=count(xd); //int cyf=stoi(wyn); ++ile[wyn[0]-'0']; if(j==tab[idx].f){ for(int i=0; i<=9; ++i){ prt[tab[idx].s]+=to_string(ile[i]); prt[tab[idx].s]+=" "; //cout<<ile[i]<<" "; } //cout<<nw; ++idx; } //cout<<i<<": "<<wyn<<nw; } for(int i=0; i<t; ++i){ cout<<prt[i]<<nw; } } |
English