首页 > 其他 > 详细

SGU 105

时间:2014-03-05 17:34:35      阅读:467      评论:0      收藏:0      [点我收藏+]

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


找规律易知会出现011 011 ..... 011 的情况(0代表不可div,1代表可div) 推公式直接输出即可。
bubuko.com,布布扣
 1 #include <iostream>
 2 #include <cstdio>
 3 
 4 using namespace std;
 5 
 6 long long n;
 7 int a[3] = {0,0,1};
 8 int main()
 9 {
10     scanf("%I64d",&n);
11 
12     printf("%d\n",n / 3 * 2 + a[n % 3] );
13     return 0;
14 }
View Code

SGU 105,布布扣,bubuko.com

SGU 105

原文:http://www.cnblogs.com/hyxsolitude/p/3581278.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!