#include <iostream>
#include <math.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n,pom,potega=0;
unsigned long long a,b,wynik=0;
bool xoxo=true;
cin>>n;
cin>>b;
for(int j=0;j<n-1;++j)
{
a=b;
cin>>b;
pom=0;
if(xoxo==true)
{
if(a>=b)
{
for(unsigned long long i=10;i<pow(10,100);i=i*10)
{
pom++;
if(a<b*i)
{
b=b*i;
wynik+=pom;
break;
}
else if(a-(b*i)<pow(10,pom)-1)
{
b=b*i+(a-(b*i)+1);
wynik+=pom;
break;
}
}
if(b>10000000000000000)
{
xoxo=false;
for(;;)
{
potega++;
b=b/10;
if(b<1000000000000000)break;
}
}
}
}
else
{
for(;;)
{
if(b>99999999999999 && b<10000000000000000)break;
pom++;
b=b*10;
}
if(b<a)
{
if(a-b<pow(10,pom)-1)
{
b+=a-b+1;
}
else potega++;
}
wynik+=pom+potega;
}
}
cout<<wynik;
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 69 70 71 72 73 | #include <iostream> #include <math.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n,pom,potega=0; unsigned long long a,b,wynik=0; bool xoxo=true; cin>>n; cin>>b; for(int j=0;j<n-1;++j) { a=b; cin>>b; pom=0; if(xoxo==true) { if(a>=b) { for(unsigned long long i=10;i<pow(10,100);i=i*10) { pom++; if(a<b*i) { b=b*i; wynik+=pom; break; } else if(a-(b*i)<pow(10,pom)-1) { b=b*i+(a-(b*i)+1); wynik+=pom; break; } } if(b>10000000000000000) { xoxo=false; for(;;) { potega++; b=b/10; if(b<1000000000000000)break; } } } } else { for(;;) { if(b>99999999999999 && b<10000000000000000)break; pom++; b=b*10; } if(b<a) { if(a-b<pow(10,pom)-1) { b+=a-b+1; } else potega++; } wynik+=pom+potega; } } cout<<wynik; return 0; } |
English