牛客网暑假多校赛第四场K题---《题解尽在代码中系列》
作者:
良袖
,
2022-08-04 12:09:49
,
所有人可见
,
阅读 199
原题链接:https:
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define lowbit(x) (x&(-x))
typedef long double db;
typedef __int128 ll;
typedef vector<int> VI;
typedef pair<int, int> PII;
const db PI = acos(-1);
const ll mod = 1e9 + 7;
const int inf_max = 0x3f3f3f3f;
const int inf_min = ~0x3f3f3f3f;
const ll inf_max_ll = 0x3f3f3f3f3f3f3f3f;
const ll inf_min_ll = ~0x3f3f3f3f3f3f3f3f;
ll Max(ll a, ll b) { return a > b ? a : b; }
ll Min(ll a, ll b) { return a < b ? a : b; }
ll Abs(ll x) { return x ? x : -x; }
ll binpow(ll a, ll b) { ll res = 1; a %= mod; while (b > 0) { if (b & 1)res = res * a % mod; a = a * a % mod; b >>= 1; } return res; }
ll inv(ll x) { return binpow(x, mod - 2); }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
int main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int n;cin>>n;
if(n==1){
cout<<0;return 0;
}
int ans=1;
rep(i,2,n){
int nxt=i%n;
ll l=i-1,r=i-1,res=0;
while(1){
res++;
l=l*10;
r=r*10+9;
assert(r<=1e15);
if(r-l+1>=n)break;
int a=l%n,b=r%n;
if(a<=b){if(a<=nxt&&nxt<=b)break;}
else{if((nxt>=0&&nxt<=b)||(nxt<n&&nxt>=a))break;}
}
ans+=res;
}
cout<<ans<<endl;
return 0;
}