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

CodeForces628-B.New Skateboard的更多相关文章

  1. 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 ...

  2. CF 628B New Skateboard --- 水题

    CD 628B 题目大意:给定一个数字(<=3*10^5),判断其能被4整除的连续子串有多少个 解题思路:注意一个整除4的性质: 若bc能被4整除,则a1a2a3a4...anbc也一定能被4整 ...

  3. CodeForces 628B New Skateboard

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

  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. Codeforces 628 B.New Skateboard

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

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

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

  7. CodeForces 628B New Skateboard 思维

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

  8. Codefroces B. New Skateboard

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

  9. New Skateboard

    Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new ...

随机推荐

  1. 一些常用的vim编辑器快捷键:

    一些常用的vim编辑器快捷键: h」.「j」.「k」.「l」,分别控制光标左.下.上.右移一格. 按「ctrl」+「b」:屏幕往“后”移动一页. 按「ctrl」+「f」:屏幕往“前”移动一页. 按「c ...

  2. jsp程序设计:jstl之JSTL标签库

    转载自:http://www.blogjava.net/haizhige/archive/2008/10/26/236783.html,个人进行了一些修改. 前言:写一个taglib一般可以继承Sim ...

  3. Linux发行版 CentOS6.5 禁用防火墙步骤

    本文地址http://comexchan.cnblogs.com/,尊重知识产权,转载请注明出处,谢谢! 注意:此操作需要使用root权限执行 首先查询防火墙状态: service iptables ...

  4. PHP array_map()

    PHP array_map() 函数 将函数作用到数组中的每个值上,每个值都乘以本身,并返回带有新值的数组: <?php function myfunction($v) { return($v* ...

  5. SQL奇技淫巧

    1.SQL行列转换 问题:假设有张学生成绩表(tb)如下:姓名 课程 分数张三 语文 74张三 数学 83张三 物理 93李四 语文 74李四 数学 84李四 物理 94想变成(得到如下结果): 姓名 ...

  6. 区分javascript中的toString(),toLocaleString(),valueOf()方法

    首先我们随意创建一个对象,这很简单,打开FF浏览器的Firebug切换到控制台或者打开webkit浏览器的审查元素功能. 输入以下内容: var obj1=[1,2,3,4,5] var obj2=[ ...

  7. CSS 去掉inline-block间隙的几种方法

    最近做移动端页面时,经常会用到inline-block元素来布局,但无可避免都会遇到一个问题,就是inline-block元素之间的间隙.这些间隙会导致一些布局上的问题,需要把间隙去掉.对于inlin ...

  8. js知识点图解

  9. Git详解之三:Git分支

    Git 分支 几乎每一种版本控制系统都以某种形式支持分支.使用分支意味着你可以从开发主线上分离开来,然后在不影响主线的同时继续工作.在很多版本控制系统中,这是个昂贵的过程,常常需要创建一个源代码目录的 ...

  10. linux大文件分包压缩和批量解压命令tar // tar 排除指定目录

    压缩命令主要用到tar打包和split分割,命令如下: tar czf - aaa | split -b 1024m - bbb.tar.gz_ aaa可以是文件也可以是目录, 大小可以是b.k.m这 ...