SGU 105

There is sequence 1, 12, 123, 1234, ..., 12345678910, ... . Given first N elements of that sequence. You must determine amount of numbers in it that are divisible by 3.

Input

Input contains N (1<=N<=231 - 1).

Output

Write answer to the output.

Sample Input

4

Sample Output

2


找规律易知会出现011 011 ..... 011 的情况(0代表不可div,1代表可div) 推公式直接输出即可。
 1 #include <iostream>
 2 #include <cstdio>
 3 
 4 using namespace std;
 5 
 6 long long n;
 7 int a[3] = {0,0,1};
 8 int main()
 9 {
10     scanf("%I64d",&n);
11 
12     printf("%d\n",n / 3 * 2 + a[n % 3] );
13     return 0;
14 }
View Code

 

posted @ 2014-03-04 22:04  hyx1  阅读(166)  评论(0编辑  收藏  举报