博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1136 - Division by 3
阅读量:4493 次
发布时间:2019-06-08

本文共 1115 字,大约阅读时间需要 3 分钟。

题意:There is sequence 1, 12, 123, 1234, ..., 12345678910, ... . Now you are given two integers A and B, you have to find the number of integers from Ath number to Bth (inclusive) number, which are divisible by 3.

For example, let A = 3. B = 5. So, the numbers in the sequence are, 123, 1234, 12345. And 123, 12345 are divisible by 3. So, the result is 2.

思路:找到规律,1 0 0 1 0 0 1 0 0......(1不能被3整除,0能被3整除),然后就是细节问题,但还是w了好几次.......- -!

题目链接:

 

View Code
1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 using namespace std; 8 9 int main(){10 11 // freopen("data.in","r",stdin);12 // freopen("data.out","w",stdout);13 14 int t,a,b,i;15 scanf("%d",&t);16 for(i=1;i<=t;i++){17 scanf("%d%d",&a,&b);18 int sum=0;19 if(a%3!=1){20 if(a%3==2){sum+=2;a+=2;}21 else {sum++;a++;} 22 }23 if(b%3!=1){24 if(b%3==2) {sum++;b--;}25 else {sum+=2;b-=2;}26 }27 printf("Case %d: %d\n",i,sum+b-a-(b-a)/3);28 }29 return 0;30 }

转载于:https://www.cnblogs.com/Hug-Sea/articles/2500977.html

你可能感兴趣的文章
Centos下搭建FTP服务器基础笔记
查看>>
jpa-入门.缓存配置ehcache.xml
查看>>
krpano 常用标签
查看>>
21069207《Linux内核原理与分析》第四周作业
查看>>
Linux系统中“动态库”和“静态库”那点事儿
查看>>
《linux备份与恢复之一》.tar.bz2与.tar.gz格式的文本压缩率比较
查看>>
005_nginx414_nginx 414 Request-URI Too Large
查看>>
Spring源码情操陶冶-ContextLoader
查看>>
Spring源码情操陶冶-PathMatchingResourcePatternResolver路径资源匹配溶解器
查看>>
C++数据结构大作业之大数加法、乘法、幂运算
查看>>
C++编程对缓冲区的理解
查看>>
windows下 安装 rabbitMQ 及操作常用命令
查看>>
Linux中 bash_profile和.bashrc的区别(启动文件)
查看>>
Tomcat出现java.lang.Exception: Socket bind failed
查看>>
AngularJS
查看>>
DBCP、C3P0、Proxool 、 BoneCP开源连接池的比较
查看>>
[.NET WebAPI系列01] WebAPI 简单例子
查看>>
[leetcode] Minimum Path Sum
查看>>
PAT乙级1021.个位数统计(15 分)
查看>>
强化学习Q-Learning算法详解
查看>>