#include<iostream>
#include<cmath>
using namespace std;
int ile_liczb(int x ) {
int n = 0;
while(x > 1 ) {
x /= 10;
n++;
}
return n;
}
int main() {
int n;
cin >> n;
int a[n];
for(int i = 0; i < n; i++ ) {
cin >> a[i];
}
int poprzedni = 0, teraz, x;
long long liczba = 0;
int y;
for(int i = 0; i < n; i++ ) {
teraz = a[i];
while(teraz <= poprzedni ) {
liczba++;
y = ile_liczb(poprzedni) - ile_liczb(teraz);
int cos = poprzedni / pow(10, y);
if(cos == teraz && y != 0 ) {
if(poprzedni < (teraz + 1) * pow(10, y) - 1 ) {
teraz = poprzedni + 1;
}else
teraz = (poprzedni - 9 ) * 10;
x = ((teraz / 10 ) * 10 ) / a[i];
liczba += log10(x) - 1;
} else
teraz *= 10;
}
poprzedni = teraz;
}
cout << liczba;
}
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 | #include<iostream> #include<cmath> using namespace std; int ile_liczb(int x ) { int n = 0; while(x > 1 ) { x /= 10; n++; } return n; } int main() { int n; cin >> n; int a[n]; for(int i = 0; i < n; i++ ) { cin >> a[i]; } int poprzedni = 0, teraz, x; long long liczba = 0; int y; for(int i = 0; i < n; i++ ) { teraz = a[i]; while(teraz <= poprzedni ) { liczba++; y = ile_liczb(poprzedni) - ile_liczb(teraz); int cos = poprzedni / pow(10, y); if(cos == teraz && y != 0 ) { if(poprzedni < (teraz + 1) * pow(10, y) - 1 ) { teraz = poprzedni + 1; }else teraz = (poprzedni - 9 ) * 10; x = ((teraz / 10 ) * 10 ) / a[i]; liczba += log10(x) - 1; } else teraz *= 10; } poprzedni = teraz; } cout << liczba; } |
English