SGU105【找规律】
来源:互联网 发布:windows7旗舰版优化 编辑:程序博客网 时间:2024/05/01 20:55
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<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<list>#include<vector>using namespace std;int main(){long long n,ans,i;while(scanf("%I64d",&n)!=EOF){//2 3 5 6 8 9if(n%3==0){printf("%lld\n",(n/3)*2);}else {long long temp=0;for(i=n+1;true;++i){if((i*(i+1)/2)%3==0)temp++;if(i%3==0)break;}printf("%lld\n",(i/3)*2-temp);}}return 0;}
0 0
- SGU105【找规律】
- SGU105
- Sgu105
- sgu105
- 找规律
- 找规律!
- 找规律
- 找规律,
- 找规律
- 找规律
- 找规律
- 找规律
- 找规律
- 找规律
- 找规律
- 找规律
- 找规律
- 递归(找规律、找出口)
- .xsession-errors:openConnection: connect: No such file or directory cannot connect to brltty at :0
- Tomcat源码解析-整体流程介绍2
- S3 Multi Part Upload 中断后续传
- 项目版本控制
- Linux学习笔记:SQLyog链接linux虚拟机上的mysql数据库
- SGU105【找规律】
- game design原理系列学习笔记(四)
- Maven自动生成可运行jar包并将依赖的jar包一起打包
- 235. Lowest Common Ancestor of a Binary Search Tree&&236. Lowest Common Ancestor of a Binary Tree
- ios 各种证书 详解
- bzoj 4597: [Shoi2016]随机序列
- iOS多线程编程技术之NSThread、Cocoa NSOperation、GCD
- This is usually because the "vboxsf" file system is not available.
- 阅读下面类的定义,请说出在测试函数中的不同情况的调用产生的结果1