SGU-105-Div 3(簡単な数学の問題!)
SGU - 105
Div 3
Time Limit: 250MS
Memory Limit: 4096KB
64bit IO Format: %I64d & %I64u
Submit 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
Sample Output
Source
数学の問題!法則を探せ!
法則:0,1,1,0,1,0,1,1,0,1,1...(0代表は3で除かれず、1代表は3で除かれる!)
ACコード:
Div 3
Time Limit: 250MS
Memory Limit: 4096KB
64bit IO Format: %I64d & %I64u
Submit 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,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
", ans);
return 0;
}