codeforces 628B B. New Skateboard (数论)
1 second
256 megabytes
standard input
standard output
Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4.
You are given a string s consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero.
A substring of a string is a nonempty sequence of consecutive characters.
For example if string s is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to usegets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead ofScanner/System.out in Java.
The only line contains string s (1 ≤ |s| ≤ 3·105). The string s contains only digits from 0 to 9.
Print integer a — the number of substrings of the string s that are divisible by 4.
Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
- 124
- 4
- 04
- 3
- 5810438174
- 9
题意:问给的这串数,它的子串是4的倍数有多少个;
思路:100的倍数一定是4的倍数,所以只用判断个位和十位就好;
AC代码:
- #include <bits/stdc++.h>
- using namespace std;
- const int N=1e5+4;
- char str[3*N];
- int a,b;
- int main()
- {
- scanf("%s",str);
- int len=strlen(str);
- long long ans=0;
- a=str[0]-'0';
- if(a%4==0)ans++;
- for(int i=1;i<len;i++)
- {
- a=str[i]-'0';
- if(a%2==0)
- {
- if(a%4==0)
- ans++;
- b=str[i-1]-'0';
- if((b*10+a)%4==0)
- {
- ans+=i;
- }
- }
- }
- cout<<ans<<"\n";
- return 0;
- }
codeforces 628B B. New Skateboard (数论)的更多相关文章
- [CodeForces - 1225D]Power Products 【数论】 【分解质因数】
[CodeForces - 1225D]Power Products [数论] [分解质因数] 标签:题解 codeforces题解 数论 题目描述 Time limit 2000 ms Memory ...
- Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论
Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论 题意 给你一段数,然后小明去猜某一区间内的gcd,这里不一定是准确值,如果在这个区间内改变 ...
- CodeForces 628B New Skateboard
New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- CodeForces 628B New Skateboard 思维
B. New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces 55D (数位DP+离散化+数论)
题目链接: http://poj.org/problem?id=2117 题目大意:统计一个范围内数的个数,要求该数能被各位上的数整除.范围2^64. 解题思路: 一开始SB地开了10维数组记录情况. ...
- Codeforces 833A The Meaningless Game - 数论 - 牛顿迭代法 - 二分法
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting. T ...
- Codeforces 837E Vasya's Function - 数论
Vasya is studying number theory. He has denoted a function f(a, b) such that: f(a, 0) = 0; f(a, b) = ...
- Codeforces 837D Round Subset - 动态规划 - 数论
Let's call the roundness of the number the number of zeros to which it ends. You have an array of n ...
- Codeforces 955C - Sad powers(数论 + 二分)
链接: http://codeforces.com/problemset/problem/955/C 题意: Q次询问(1≤Q≤1e5),每次询问给出两个整数L, R(1≤L≤R≤1e18),求所有符 ...
随机推荐
- Smart pointer 智能指针小总结
Smart pointer line 58之后smart pointer里的计数已经是0,所以会真正释放它引用的对象,调用被引用对象的析构函数.如果继续用指针访问,会出现如下图的内存访问异常.所以说如 ...
- UVA 699 The Falling Leaves (二叉树水题)
本文纯属原创.转载请注明出处,谢谢. http://blog.csdn.net/zip_fan. Description Each year, fall in the North Central re ...
- PHP-Manual的学习----【语言参考】----【类型】-----【Resource 资源类型】
2017年8月24日11:29:361.资源 resource 是一种特殊变量,保存了到外部资源的一个引用.资源是通过专门的函数来建立和使用的.2.由于资源类型变量保存有为打开文件.数据库连接.图形画 ...
- Lumen开发:结合Redis实现消息队列(3)
4.运行队列监听器 开启任务监听器 Lumen包含了一个Artisan命令用来运行推送到队列的新任务.你可以使用queue:listen命令运行监听器: php artisan queue:liste ...
- centos7.0安装redis扩展
1.下载 下载地址:https://github.com/phpredis/phpredis/ 文件名:phpredis-develop.zip 文件下载成功后,上传至/usr/local 2.安装 ...
- centos7.0 安转mysql5.7
安装mysql5.7需要boost依赖包groupadd mysql useradd -r -g mysql -s /bin/false mysql cmake . -DCMAKE_INSTALL_P ...
- tomcat6指定的服务为安装
tomcat6w.exe 运行 提示 指定的服务未安装 unable to open the service 'tomcat6' 新下载的Tomcat6.0.29 解压版,解压缩完成后,双击tomca ...
- IIS架构介绍
IIS7及以上版本提供的请求-处理架构包括以下内容: Windows Process Activation Service(WAS)可以让站点支持更多协议,不仅仅是HTTP和HTTPS 可以通过增加或 ...
- ElasticSearch(二十七)type的数据结构
1.什么是type? type,是一个index中用来区分类似的数据的,类似的数据,但是可能有不同的fields,而且有不同的属性来控制索引建立.分词器field的value,在底层的lucene中建 ...
- 洛谷 P2051 [SDOI2009]学校食堂
传送门- 题目分析:首先,我们先看看做菜时间的运算机制.$(A~\texttt{or}~B)-(A~\texttt{and}~B)$这个试子看起来有点复杂(因为我太菜了),仔细想想,是不是可以转化为$ ...