您的位置:首页 > 其它

sgu105-数学

2014-04-23 15:14 316 查看

105. Div 3

time limit per test: 0.25 sec. memory limit per test: 4096 KBThere 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.InputInput contains N (1<=N<=231 - 1).OutputWrite 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;}
[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: