SGU 105. Div 3

 

105. Div 3

time limit per test: 0.5 sec. 
memory limit per test: 4096 KB

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

 
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
    int n;
    while(cin>>n)
    {
        unsigned long long int ans=0;
        if(n%3==0) ans=2;
        if(n%3==2) ans=1;
        ans+=(n-1)/3*2;
        cout<<ans<<endl;
    }
    return 0;
}
* This source code was highlighted by YcdoiT. ( style: Trac )
posted @ 2013-08-18 21:11  码代码的猿猿  阅读(139)  评论(0编辑  收藏  举报