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 ;
}

Codeforces 628 B.New Skateboard的更多相关文章

  1. codeforces 628B B. New Skateboard (数论)

    B. New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  2. CodeForces 628 D Magic Numbers 数位DP

    Magic Numbers 题意: 题意比较难读:首先对于一个串来说, 如果他是d-串, 那么他的第偶数个字符都是是d,第奇数个字符都不是d. 然后求[L, R]里面的多少个数是d-串,且是m的倍数. ...

  3. Codeforces CF#628 Education 8 B. New Skateboard

    B. New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  4. Educational Codeforces Round 8 B. New Skateboard 暴力

    B. New Skateboard 题目连接: http://www.codeforces.com/contest/628/problem/A Description Max wants to buy ...

  5. Educational Codeforces Round 8 B. New Skateboard

    题目链接:http://codeforces.com/problemset/problem/628/B 解题思路: 一个数最后两位数能被4整除那么这个数就能被4整除,而且题目还是连续的子序列,这就很简 ...

  6. CodeForces 628B New Skateboard

    New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  7. CodeForces 628B New Skateboard 思维

    B. New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  8. Codeforces CF#628 Education 8 F. Bear and Fair Set

    F. Bear and Fair Set time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  9. Codeforces CF#628 Education 8 E. Zbazi in Zeydabad

    E. Zbazi in Zeydabad time limit per test 5 seconds memory limit per test 512 megabytes input standar ...

随机推荐

  1. PaaS服务之路漫谈(一)

    此文已由作者尧飘海授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. PaaS服务之路漫谈(一) 1983年,SUN公司提出的网络即计算的理念:2006年亚马逊(Amazon)推 ...

  2. 【转载】Linux下安装LoadRunner LoadGenerator

    原文地址:[转载]Linux下安装LoadRunner LoadGenerator作者:邱建忠tester LR的负载机安装在linux的理由: 1.windows xp,双核+4G内存,基本上每个v ...

  3. Python之日志处理 logging模块

    Python之日志处理(logging模块)   本节内容 日志相关概念 logging模块简介 使用logging提供的模块级别的函数记录日志 logging模块日志流处理流程 使用logging四 ...

  4. 2、shader基本语法、变量类型、shader的三种形式、subshader、fallback、Pass LOD、tags

    新建一个shader,名为MyShader1内容如下: 1._MainTex 为变量名 2.“Base (RGB)”表示在unity编辑面板中显示的名字,可以定义为中文 3.2D 表示变量的类型 4. ...

  5. php设计模式 工厂模式和单例

    1.单例模式//让该类在外界无法造对象//让外界可以造一个对象,做一个静态方法返回对象//在类里面通过让静态变量控制返回对象只能是一个. class cat{ public $name; privat ...

  6. SQL 唯一标识 写法

    创建唯一标识的方法~16位唯一标识 SELECT LTRIM(STR(CONVERT(varchar(100), GETDATE(), 112)))+right(cast(power(10,6) as ...

  7. 三十道DP练习(持续更新)(pw:DP)

    前言: 话说DP这种纯考思维的题目,总是让我很伤脑筋,一些特别简单的DP我都常常做不出来,所以革命从现在(2018-05-01)开始,努力多刷点DP的练习-. 1.顺序对齐(align) 时间:201 ...

  8. 【CF #313】

    B题为啥交换一下搜索顺序就会TLE啊QAQ C题原来要预处理乘法逆元才能过啊QAQ 我沙茶啊我QAQ[还是太弱 嗯A题就是道水题 B题就是字符串Hash+暴力搜 C题就是组合数+容斥原理

  9. POJ 3180 The cow Prom Tarjan基础题

    题目用google翻译实在看不懂 其实题目意思如下 给一个有向图,求点个数大于1的强联通分量个数 #include<cstdio> #include<algorithm> #i ...

  10. 洛谷 P3765 总统选举 解题报告

    P3765 总统选举 题目背景 黑恶势力的反攻计划被小C成功摧毁,黑恶势力只好投降.秋之国的人民解放了,举国欢庆.此时,原秋之国总统因没能守护好国土,申请辞职,并请秋之国人民的大救星小C钦定下一任.作 ...