Skip to content

Instantly share code, notes, and snippets.

@devgenjin77
Created March 14, 2021 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devgenjin77/963b9decb6b8077b5c6691082e568e94 to your computer and use it in GitHub Desktop.
Save devgenjin77/963b9decb6b8077b5c6691082e568e94 to your computer and use it in GitHub Desktop.
static long solve(long n){
if(n < 1000){
return 0;
}
long ans = 0;
if(n >= 1_000_000_000_000_000l){
ans += 5;
}
if(n >= 1_000_000_000_000l){
ans += (Math.min(1_000_000_000_000_000l - 1, n) - (1_000_000_000_000l - 1)) * 4;
}
if(n >= 1_000_000_000l){
ans += (Math.min(1_000_000_000_000l - 1, n) - (1_000_000_000l - 1)) * 3;
}
if(n >= 1_000_000l){
ans += (Math.min(1_000_000_000l - 1, n) - (1_000_000l - 1)) * 2;
}
if(n >= 1_000l){
ans += (Math.min(1_000_000l - 1, n) - (1_000l - 1)) * 1;
}
return ans;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment