Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.math.BigInteger;
  4.  
  5. public class Solution {
  6.    
  7.     private void solution() throws IOException {
  8.         int a = in.nextInt();
  9.         out.println(solve(a));
  10. //      int sum = 0;
  11. //      String number = "";
  12. //      for (int i = 1; i < 100000; ++i) {
  13. //          number += i;
  14. //          if (((new BigInteger(number)).mod(BigInteger.valueOf(3)).equals(BigInteger.ZERO))) {
  15. //              ++sum;
  16. //          }
  17. //          if (sum != solve(i)) {
  18. //              out.println("for i = " + i + " ans = { " + sum + "->" + solve(i) + " }");
  19. ////                out.println(i + " " + sum + " " + number);
  20. //          }
  21. //      }
  22.         out.flush();
  23.     }
  24.  
  25.     private int solve(int a) {
  26.         if (a == 1) {
  27.             return 0;
  28.         }
  29.         int mod = (a - 2) % 3;
  30.         if (mod == 0) {
  31.             return get(a);
  32.         }
  33.         int left = a - mod;
  34.         return get(left) + 1;
  35.     }
  36.  
  37.     private int get(int a) {
  38.         return ((a - 2) / 3) * 2 + 1;
  39.     }
  40.  
  41.     private class Scanner {
  42.         BufferedReader reader;
  43.         StringTokenizer tokenizer;
  44.  
  45.         public Scanner(Reader reader) {
  46.             this.reader = new BufferedReader(reader);
  47.             this.tokenizer = new StringTokenizer("");
  48.         }
  49.  
  50.         public boolean hasNext() throws IOException {
  51.             while (!tokenizer.hasMoreTokens()) {
  52.                 String next = reader.readLine();
  53.                 if (next == null) {
  54.                     return false;
  55.                 }
  56.                 tokenizer = new StringTokenizer(next);
  57.             }
  58.             return true;
  59.         }
  60.  
  61.         public String next() throws IOException {
  62.             hasNext();
  63.             return tokenizer.nextToken();
  64.         }
  65.  
  66.         public int nextInt() throws IOException {
  67.             return Integer.parseInt(next());
  68.         }
  69.  
  70.         public String nextLine() throws IOException {
  71.             tokenizer = new StringTokenizer("");
  72.             return reader.readLine();
  73.         }
  74.     }
  75.  
  76.     public static void main(String[] args) throws IOException {
  77.         (new Solution()).solution();
  78.     }
  79.    
  80.     PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
  81.     Scanner in = new Scanner(new InputStreamReader(System.in));
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement