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
解题思路:
水题,找规律
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#define LL long long
using namespace std;
int main()
{
LL n;
while(scanf("%lld", &n)!=EOF)
{
LL ans = (n / 3) * 2;
if(n % 3 > 0) ans += (n % 3) - 1;
printf("%lld\n", ans);
}
return 0;
}