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整除。因为100可以被4整除,所以100位以上的都可以,只要看个位和十位的数是否可以被4整除。
写这个题的时候傻了,只是算一下个位和十位就好了,然后把前面的位数加上就可以了,。
因为想一下,举个例子,xyzab,如果ab%4==0,那么xyzab可以组成多少个子串呢?那就是ab,zab,yzab,xyzab,就是a所在的位置啊,因为是从0开始的,所以位数+1,我可能是个傻子。。。
这样这道题就可以a了。

代码:

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=*1e5+;
char a[N];
int main(){
while(~scanf("%s",a)){
ll len,cnt,ans;
len=strlen(a);
ans=;
for(int i=;i<len;i++){
if((a[i]-'')%==)ans++;
}
for(int i=;i<len-;i++){
cnt=(a[i]-'')*+(a[i+]-'');
if(cnt%==)ans+=i+;
}
cout<<ans<<endl;
}
return ;
}

最新文章

  1. Redis系列一之数据结构
  2. iOS开发--应用设置及用户默认设置【2、读取应用中的设置】
  3. OpenGL-选择与拾取
  4. javascrpt随笔
  5. JAXB--学习2
  6. 黄聪:Microsoft Enterprise Library 5.0 系列教程(六) Security Application Block
  7. S3C2440之IIC裸机驱动
  8. [Linux] PHP程序员玩转Linux系列-lnmp环境的搭建
  9. Android 结合实际项目学会ListView局部刷新和相关知识《一》
  10. 洛谷P2120 [ZJOI2007]仓库建设 斜率优化DP
  11. [swarthmore cs75] Lab 0 Warmup &amp; Basic OCaml
  12. Codeforces 741D Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths(dsu on tree)
  13. hihoCoder week19 RMQ问题再临-线段树 单点更新 区间查询
  14. 记一次排查局网内的ARP包 “不存在的” MAC 地址及 “不存在的”IP 所发的ARP包
  15. grafana,graphite,influxdb with docker
  16. 在VS中让一个JS文件智能提示另一个JS文件中的成员2--具体引用
  17. Oracle win32_11gR2_client.zip
  18. MQTT的学习研究(十)【转】mosquitto——一个开源的mqtt代理
  19. la3523 白书例题 圆桌骑士 双联通分量+二分图
  20. 移动端base.css

热门文章

  1. 18、bootStap JavaScript插件
  2. APP测试用例要考虑的一些方面
  3. win10 64位 C# 连接oracle 32位, 遇到的问题及解决
  4. linux shell 总结 (整理)
  5. ASP.NET Core ---异常处理
  6. leetcode_day02
  7. PHP基础壹
  8. Android记事本11
  9. Android记事本10
  10. h5滚动条加载到底部