abc 363D
作者:
Air1222
,
2024-10-02 18:20:43
,
所有人可见
,
阅读 2
//10+9+9*10+9*10+9*10*10...
//9*10^(ceil(n/2)-1)
//9^ceil(n/2)
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long LL;
LL x;
int main()
{
cin>>x;
if(x<=10) cout<<x-1;
else
{
x-=10;
LL n=2;
LL temp=9;
// while(temp<=x) //优质写法
// {
// x-=temp;
// n++;
// if(n%2==1)
// temp*=10;
// }
while(9ll*pow(10,ceil((double)n/2)-1)<=x)
{
//LL temp=9ll*pow(10,ceil((double)n/2)-1);//pow(产出为浮点数,要强制转化为long long,否则会溢出)
x-=9ll*(LL)pow(10,ceil((double)n/2)-1);
n++;
}
//cout<<x<<endl;
//cout<<x-9<<endl;
LL ans=pow(10,ceil((double)n/2)-1);
ans+=x-1;
//cout<<ans<<endl;
string res=to_string(ans);
if(n%2==0)
{
cout<<res;
for(int i=res.size()-1;i>=0;i--) cout<<res[i];
}
else
{
cout<<res;
for(int i=res.size()-2;i>=0;i--) cout<<res[i];
}
}
}