找呀找呀找规律,找到一个好规律

Description

有一天,天上掉下来连续N个数,1, 12, 123, 1234, ..., 12345678910,....这时天上掉下来一个天使,问它你知道这N个数有多少个能被3整除么?

Input

输入一个 N (1<=N<= 10^8).

你需要处理到文件结束(EOF)

 

 

Output

输出答案

Sample Input

4

Sample Output

2

HINT

同余,不能能/不能能/不能能.....的规律

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 #include <string>
 5 #include <algorithm>
 6 using namespace std;
 7 int main(){
 8     int N;
 9     while(scanf("%d", &N) != EOF){
10         if(N%3 == 0 || N%3 == 1) printf("%d\n", N/3*2);
11         else if(N%3 == 2) printf("%d\n", N/3*2+1);
12     
13     }
14     return 0;
15 }

 

posted @ 2015-03-16 17:05  下周LGD该赢了吧  阅读(97)  评论(0编辑  收藏  举报