sgu-105
来源:互联网 发布:win10多核优化 编辑:程序博客网 时间:2024/04/30 23:57
105. Div 3
time limit per test: 0.5 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
acm能做的时间是短暂的,努力在有限的时间抓紧时间学习
分析
对小数据做一些观察,比如前6个数:
1,12,123,1234,12345,123456。
如果用1表示可以被3整除,0表示不能被3整除,则上述序列可表为:
0,1,1,0,1,1。
我们可以发现一个明显的模式:011,011,011,…。也就是一个不能被3整除,然后两个可以,然后又是一个不可以,循环往复。
这结论可以通过数学归纳法证明。
#include<stdio.h>int main(){ int n; while(~scanf("%d",&n)) printf("%d\n",n/3*2+(n%3==2)); return 0;}
- sgu-105
- 【sgu】105 解题报告
- SGU 105 Div 3
- sgu 105 Div 3
- sgu 105 Div 3
- sgu 105 水
- SGU 105 Div 3
- SGU 105 div3
- SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- (SGU
- SGU
- SGU
- SGU
- nyoj-106
- nyoj-107
- nyoj-108
- hdu-1172
- nyoj-109
- sgu-105
- poj-2696
- 再发一种基于stm32的4X4矩阵键盘定时器扫描消抖法,彻底告别delay函数! .
- nyoj-112
- nyoj-116
- zstu-2605
- nyoj-54
- Zen Cart学习 – Zen Cart模块快速开发文档
- wikioi-1742