您的位置:首页 > 其它

SGU 105

2014-03-04 22:04 127 查看
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) 推公式直接输出即可。


#include <iostream>
#include <cstdio>

using namespace std;

long long n;
int a[3] = {0,0,1};
int main()
{
scanf("%I64d",&n);

printf("%d\n",n / 3 * 2 + a[n % 3] );
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: