Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- import java.math.BigInteger;
- public class Solution {
- private void solution() throws IOException {
- int a = in.nextInt();
- out.println(solve(a));
- // int sum = 0;
- // String number = "";
- // for (int i = 1; i < 100000; ++i) {
- // number += i;
- // if (((new BigInteger(number)).mod(BigInteger.valueOf(3)).equals(BigInteger.ZERO))) {
- // ++sum;
- // }
- // if (sum != solve(i)) {
- // out.println("for i = " + i + " ans = { " + sum + "->" + solve(i) + " }");
- //// out.println(i + " " + sum + " " + number);
- // }
- // }
- out.flush();
- }
- private int solve(int a) {
- if (a == 1) {
- return 0;
- }
- int mod = (a - 2) % 3;
- if (mod == 0) {
- return get(a);
- }
- int left = a - mod;
- return get(left) + 1;
- }
- private int get(int a) {
- return ((a - 2) / 3) * 2 + 1;
- }
- private class Scanner {
- BufferedReader reader;
- StringTokenizer tokenizer;
- public Scanner(Reader reader) {
- this.reader = new BufferedReader(reader);
- this.tokenizer = new StringTokenizer("");
- }
- public boolean hasNext() throws IOException {
- while (!tokenizer.hasMoreTokens()) {
- String next = reader.readLine();
- if (next == null) {
- return false;
- }
- tokenizer = new StringTokenizer(next);
- }
- return true;
- }
- public String next() throws IOException {
- hasNext();
- return tokenizer.nextToken();
- }
- public int nextInt() throws IOException {
- return Integer.parseInt(next());
- }
- public String nextLine() throws IOException {
- tokenizer = new StringTokenizer("");
- return reader.readLine();
- }
- }
- public static void main(String[] args) throws IOException {
- (new Solution()).solution();
- }
- PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
- Scanner in = new Scanner(new InputStreamReader(System.in));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement