fork download
  1. import java.util.*;
  2.  
  3. class Main{
  4.  
  5. public static void main(String[] args){
  6.  
  7. Scanner sc = new Scanner(System.in);
  8.  
  9. int N = sc.nextInt();
  10.  
  11. int power = 0;
  12.  
  13. while(N>=10){
  14.  
  15. power++;
  16.  
  17. N /= 10;
  18.  
  19. }
  20.  
  21. int ans = 0;
  22.  
  23. if(power%2 == 1){
  24.  
  25. for(int i=1; i<=power; i++){
  26.  
  27. if(i%2 == 1){
  28.  
  29. ans += 9*Math.pow(10,i-1);
  30.  
  31. }
  32. }
  33.  
  34. }
  35.  
  36. if(power%2 == 1){
  37.  
  38. System.out.println(ans);
  39.  
  40. }
  41.  
  42. else{
  43.  
  44. System.out.println(ans+(N+1-1*Math.pow(N,power)));
  45.  
  46. }
  47.  
  48.  
  49. }
  50. }
Success #stdin #stdout 0.1s 35424KB
stdin
100000
stdout
90909