B. New Skateboard
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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 use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.

Input

The only line contains string s (1 ≤ |s| ≤ 3·105). The string s contains only digits from 0 to 9.

Output

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.

Examples
input
124
output
4
input
04
output
3
input
5810438174
output
9

题意:给你一串数,让你找出其中有几个子串是4的倍数(包括总串)。

思路:暴搜必定超时O(n^2),我们可以分类讨论。先考虑一位数,当满足4的倍数时c++;然后是两位数,满足条件+1,这时就要考虑当两位数满足4的倍数时,前面不管再加多少位,都是4的倍数(100、1000、10000...都能被4整除),那么我们就可以把两位数前面的数字(i个)依次加上,他们分别是以两位数为尾的三位数、四位数、五位数...因此c+i+1。O(n+n)。

#include<stdio.h>
#include<string.h> int main()
{
long long c,i;
char s[];
scanf("%s",s);
c=;
for(i=;i<strlen(s);i++){
if((s[i]-'')%==) c++;
}
for(i=;i<strlen(s)-;i++){
if(((s[i]-'')*+(s[i+]-''))%==) c+=i+;
}
printf("%lld\n",c);
return ;
}

最新文章

  1. [Python] Python中的一些特殊函数
  2. NPOI操作Excel导入DataTable中
  3. loadrunner协议选择
  4. MySql错误1045 Access denied for user &#39;root&#39;@&#39;localhost&#39; (using password:YES) windows下的解决方案(忘记密码)
  5. Dynamic Percentage of Operands
  6. Windows原生MPIO存储多路径软件详解与应用
  7. php常量运用注意
  8. NET 2016
  9. A星寻路lua实现
  10. HDU 1501 Zipper(DP,DFS)
  11. java equals()方法
  12. poj3070矩阵快速幂
  13. Java集合中迭代器的常用用法
  14. Linux permission denied问题
  15. ORA-28002:the password will expire within 6 days
  16. Matplotlib学习---用matplotlib画柱形图,堆积柱形图,横向柱形图(bar chart)
  17. Luogu P5290 / LOJ3052 【[十二省联考2019]春节十二响】
  18. DB2的空间数据库管理复杂配置
  19. Oracle用imp和exp实现数据的导入和导出
  20. Ubuntu Linux自动发邮件配置及邮件发送脚本

热门文章

  1. caffe学习--caffe入门classification00学习--ipython
  2. 继承的文本框控件怎么响应EN_CHANGE等消息
  3. win7 PLSQL Developer 10/11/12 连接 Oracle 10/11/12 x64位数据库配置详解(与32位一样,只要注意对应Oracle Instant Client版本) tns 错误和 nls错误
  4. CenterOS下搭建Hadoop环境
  5. python网络爬虫之使用scrapy下载文件
  6. 使用c函数库的两个函数strtok, strncpy遇到的问题记录
  7. HTML初级教程 表单form
  8. Android 如何永久性开启adb 的root权限【转】
  9. Hihocoder #1095 : HIHO Drinking Game (微软苏州校招笔试)( *【二分搜索最优解】)
  10. POJ2389 —— 高精度乘法