SGU105 - 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
题解:规律题。。。。可以发现前N项的余数为1,0,0,1,0,0,1,0,0...
View Code
1 #include<stdio.h>

2 int main(void)

3 {

4     long n;

5     scanf("%ld",&n);

6     printf("%ld\n",n/3*2+((n%3==2)?1:0));

7     return 0;

8 }

 

 

你可能感兴趣的:(div)