sgu105-數學

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

我是根據發現規律解出來的
10
21
32
42
53
64
74
85
96
106
117
128
#include <iostream>
using namespace std;

int main()
{
    int N;
    cin >> N;
	
    int ans = 0;  
    if (N % 3 == 2)  
        ans++;  
    ans += 2 * (N / 3);  
    cout << ans; 

    return 0;
}


發佈了63 篇原創文章 · 獲贊 15 · 訪問量 18萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章