SGU105【找规律】

来源:互联网 发布:windows7旗舰版优化 编辑:程序博客网 时间:2024/05/01 20:55

105. Div 3

time limit per test: 0.25 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<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 9if(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;} 


0 0
原创粉丝点击