#include <iostream>
#include <vector>
#include <string>
using namespace std;
// Funkcja obliczająca jednocyfrowy wynik zabawy
int singleDigitResult(long long x) {
while (x >= 10) {
long long product = 1;
while (x > 0) {
product *= (x % 10);
x /= 10;
}
x = product;
}
return x;
}
int main() {
int t;
cin >> t;
vector<long long> n(t);
for (int i = 0; i < t; i++) {
cin >> n[i];
}
// Preliczanie wyników dla wszystkich liczb od 1 do 100
vector<vector<int>> precomputed(101, vector<int>(10, 0));
for (int i = 1; i <= 100; i++) {
int result = singleDigitResult(i);
precomputed[i][result]++;
}
// Sumowanie wyników do przedziałów
for (int i = 1; i <= 100; i++) {
for (int j = 0; j < 10; j++) {
precomputed[i][j] += precomputed[i - 1][j];
}
}
// Rozwiązanie dla każdego dnia
for (int i = 0; i < t; i++) {
vector<int> result(10, 0);
if (n[i] <= 100) {
for (int j = 0; j < 10; j++) {
result[j] = precomputed[n[i]][j];
}
} else {
for (int j = 0; j < 10; j++) {
result[j] = precomputed[100][j];
}
for (long long x = 101; x <= n[i]; x++) {
int digit = singleDigitResult(x);
result[digit]++;
}
}
// Wypisanie wyniku dla danego dnia
for (int j = 0; j < 10; j++) {
cout << result[j] << " ";
}
cout << endl;
}
return 0;
}
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 67 68 | #include <iostream> #include <vector> #include <string> using namespace std; // Funkcja obliczająca jednocyfrowy wynik zabawy int singleDigitResult(long long x) { while (x >= 10) { long long product = 1; while (x > 0) { product *= (x % 10); x /= 10; } x = product; } return x; } int main() { int t; cin >> t; vector<long long> n(t); for (int i = 0; i < t; i++) { cin >> n[i]; } // Preliczanie wyników dla wszystkich liczb od 1 do 100 vector<vector<int>> precomputed(101, vector<int>(10, 0)); for (int i = 1; i <= 100; i++) { int result = singleDigitResult(i); precomputed[i][result]++; } // Sumowanie wyników do przedziałów for (int i = 1; i <= 100; i++) { for (int j = 0; j < 10; j++) { precomputed[i][j] += precomputed[i - 1][j]; } } // Rozwiązanie dla każdego dnia for (int i = 0; i < t; i++) { vector<int> result(10, 0); if (n[i] <= 100) { for (int j = 0; j < 10; j++) { result[j] = precomputed[n[i]][j]; } } else { for (int j = 0; j < 10; j++) { result[j] = precomputed[100][j]; } for (long long x = 101; x <= n[i]; x++) { int digit = singleDigitResult(x); result[digit]++; } } // Wypisanie wyniku dla danego dnia for (int j = 0; j < 10; j++) { cout << result[j] << " "; } cout << endl; } return 0; } |
English