码迷,mamicode.com
首页 > 其他好文 > 详细

SGU - 105 - Div 3 (简单数学题!)

时间:2014-12-11 17:27:32      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:sgu   acm   algorithm   c++   icpc   

SGU - 105
Time Limit: 250MS   Memory Limit: 4096KB   64bit IO Format: %I64d & %I64u

 Status

Description

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

Source




数学题!找规律!


规律:0,1,1,0,1,1,0,1,1,0,1,1....      (0代表不能被3整除,1代表能被3整除!)


AC代码:


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	int ans = 0;
	ans += (n/3)*2;
	if(n%3==2) ans++;
	printf("%d\n", ans);
	return 0;
} 






SGU - 105 - Div 3 (简单数学题!)

标签:sgu   acm   algorithm   c++   icpc   

原文地址:http://blog.csdn.net/u014355480/article/details/41868809

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!