105. Div 3 time limit per test: 0.25 sec. 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<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<list>
#include<vector>
using namespace std;
int main()
{
long long n,ans,i;
while(scanf("%I64d",&n)!=EOF){
//2 3 5 6 8 9
if(n%3==0){
printf("%lld\n",(n/3)*2);
}
else {
long long temp=0;
for(i=n+1;true;++i){
if((i*(i+1)/2)%3==0)temp++;
if(i%3==0)break;
}
printf("%lld\n",(i/3)*2-temp);
}
}
return 0;
}