Education Round 8 A - New Skateboard

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 and124. 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 useBufferedReader/PrintWriter instead ofScanner/System.out in Java.

Input

The only line contains string s (1?≤?|s|?≤?3·105). The string s contains only digits from 0to 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 Javayou can use long integer type.

Example

Input

124

Output

4

Input

04

Output

3

Input

5810438174

Output

9
 1  /*首先,容易想到100是4的倍数。
 2     所以我们只用考虑后两位数字就能够判断一个数字能否被4整除,因为
 3     x*100+y=y (mod 4)
 4     其中y代表超过100的数字部分。
 5     于是只需要对所有相邻两位判断,如果某两位可以被4整除,那么以这两位结尾的所有子串都是可行的。
 6     比如12344,44能被4整除,那么44,344,2344,12344都能被4整除。
 7     在单独考虑只有一个位的子串就好。
 8    */
 9
10
11    #include <iostream>
12    #include <stdio.h>
13    #include <string.h>
14    using namespace std;
15    const int N=300010;
16    char s[N];
17    int main(){
18     long long ans=0;
19     scanf("%s",s);
20     int len=strlen(s);
21     for(int i=0;i<len;i++)
22         if((s[i]-‘0‘)%4==0) ans++;
23         for(int i=1;i<len;i++){
24             int temp=(s[i-1]-‘0‘)*10+s[i]-‘0‘;
25             if(temp%4==0) ans+=i;    ///以这两位结尾的子串
26         }
27         printf("%I64d\n",ans);/// 输出呀,WA了三次  直接用cout<< ans<<endl;也行
28     return 0;
29    }
时间: 2024-10-10 13:17:11

Education Round 8 A - New Skateboard的相关文章

Educational Codeforces Round 8 B. New Skateboard

题目链接:http://codeforces.com/problemset/problem/628/B 解题思路: 一个数最后两位数能被4整除那么这个数就能被4整除,而且题目还是连续的子序列,这就很简单了 实现代码: #include <cstdio> #include <string> #include <iostream> #include <algorithm> #include <vector> #include <queue>

Codeforces Education Round 11

A(模拟+数学) 题意:在一个数列当中最少添加多少个数可以使它们两两互质,并打印出添加以后的数列 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <string> 5 #include <vector> 6 #include <algorithm> 7 #include <set> 8 #include <map>

Spark2 DataFrameStatFunctions探索性数据统计分析

data数据源,请参考我的博客http://www.cnblogs.com/wwxbi/p/6063613.html import org.apache.Spark.sql.DataFrameStatFunctions import org.apache.spark.sql.functions._ 相关系数 val df = Range(0,10,step=1).toDF("id").withColumn("rand1", rand(seed=10)).withCo

[Educational Codeforces Round 36]E. Physical Education Lessons

[Educational Codeforces Round 36]E. Physical Education Lessons <题意概括> 给定一个长度为$N\left(1\leqslant N\leqslant10^{9}\right)$的区间 $Q\left(1\leqslant Q\leqslant3\cdot10^{5}\right)$次将区间$\left[L,R\right]$Set为0或1,每次Set后输出区间总和 <做法> $10_{9}$的范围显然不可能是朴素线段树

Educational Codeforces Round 36 (Rated for Div. 2) E. Physical Education Lessons(动态开点线段树)

链接: https://codeforces.com/problemset/problem/915/E 题意: This year Alex has finished school, and now he is a first-year student of Berland State University. For him it was a total surprise that even though he studies programming, he still has to atten

HDU 5806 NanoApe Loves Sequence Ⅱ(尺取+思维)——BestCoder Round #86 1003

传送门 NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 K (Java/Others)Total Submission(s): 514    Accepted Submission(s): 248 Problem Description NanoApe, the Retired Dog, has returned back to prepare for f

Educational Codeforces Round 36

Educational Codeforces Round 36 A. Garden 题目描述:给定\(n\)个数,找出能整除\(m\)的最大的数(假设是\(num\)),输出\(\frac{m}{num}\). solution 枚举. 时间复杂度:\(O(n)\) B. Browser 题目描述:有\(n\)个标签页,当前在第\(i\)页,有下面六个操作: 向左移动一个页面,即\(i-1\) 向右移动一个页面, 即\(i+1\) 关闭左边一个页面,即第\(i-1\)个页面 关闭右边一个页面,即

Educational Codeforces Round 40千名记

人生第二场codeforces.然而遇上了Education场这种东西 Educational Codeforces Round 40 下午先在家里睡了波觉,起来离开场还有10分钟. 但是突然想起来还没报名呢,并且电脑又是开机黑屏什么情况 莫非为之后的凉凉埋下了伏笔? 比赛之前联系了下余翱和叶可禾,似乎都要去切题的样子? 想到第一次有人一起打CF还是有点小激动的.于是果断屏蔽余翱QQ上的刷屏去看A题了. A. Diagonal Walking 非常仔细地把题读了一遍,然后……啥这不是字符串入门题

Educational Codeforces Round 21 G. Anthem of Berland(dp+kmp)

题目链接:Educational Codeforces Round 21 G. Anthem of Berland 题意: 给你两个字符串,第一个字符串包含问号,问号可以变成任意字符串. 问你第一个字符串最多包含多少个第二个字符串. 题解: 考虑dp[i][j],表示当前考虑到第一个串的第i位,已经匹配到第二个字符串的第j位. 这样的话复杂度为26*n*m*O(fail). fail可以用kmp进行预处理,将26个字母全部处理出来,这样复杂度就变成了26*n*m. 状态转移看代码(就是一个kmp