SGU105 Div 3
来源:互联网 发布:淘宝云客服工资多少 编辑:程序博客网 时间:2024/04/29 10:01
SGU105 Div 3
题目大意
对于这样一个数列:1, 12, 123, 1234, ..., 12345678910, ...
输入N,输出该数列的前N项中有多少个数能被3整除
算法思路
由于N mod 3的结果等于N的数位和 mod 3的结果
该序列等价于:1, (1 + 2) % 3 = 0, (0 + 0) % 3 = 0, (0 + 1) % 3 = 1, (1 + 2) % 3 = 0, ...
故可以直接计算结果
时间复杂度: O(1)
代码
/** * Copyright (c) 2015 Authors. All rights reserved. * * FileName: 105.cpp * Author: Beiyu Li <sysulby@gmail.com> * Date: 2015-05-21 */#include <bits/stdc++.h>using namespace std;#define rep(i,n) for (int i = 0; i < (n); ++i)#define For(i,s,t) for (int i = (s); i <= (t); ++i)#define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)typedef long long LL;typedef pair<int, int> Pii;const int inf = 0x3f3f3f3f;const LL infLL = 0x3f3f3f3f3f3f3f3fLL;int main(){ int n; scanf("%d", &n); --n; printf("%d\n", n / 3 * 2 + n % 3); return 0;}
0 0
- SGU105 Div 3
- sgu105:Div 3
- SGU105 Div 3
- sgu105: Div 3
- SGU105 Div 3
- SGU105—— Div 3
- SGU105
- Sgu105
- sgu105
- sgu105-数学
- sgu105 算是数学么。。。
- SGU105【找规律】
- SGU105 水题 An easy problem
- SGU水题大集合 SGU104 SGU105 SGU107
- div 3
- Div 3
- Div 3
- div+css (3)
- 十一月十一
- UVA 10054 The Necklace
- 领域驱动设计和开发实战
- 【iOS】UITableViewCell高度计算(固定高度+自动高度)
- 如何给activity中的控件增加事件响应代码
- SGU105 Div 3
- 大数据思维的十大原理----当样本数量足够大时,你会发现其实每个人都是一模一样的
- 《如果可以爱你》
- sqlite日期函数及时间
- ffmpeg的新东东:AVFilter
- Spark Streaming小结
- 链接与加载 动态链接与静态链接
- html Array()数组的使用
- 后缀s是如何影响标志位的