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. 小白的Python之路 day4 迭代器

    迭代器 学习前,我们回想一下可以直接作用于for循环的数据类型有以下几种: 1.集合数据类型,如list.tuple.dict.set.str等: 2.是generator,包括生成器和带yield的 ...

  2. Linux服务器上的oracle数据导入和导出

    背景: 在同一台Linux服务器上,有两个数据库用户,分别为:database1,database2,如何把database1用户下面的所有的表和数据,导入到database2数据库(database ...

  3. Thinkphp环境搭建

    一.准备工作-基础知识 1.php环境配置 配置php文件运行环境Apache,phpstudy集成环境(还有别的集成环境都可以). 2.设计数据库 根据需求设计table,可以用一些数据库管理工具n ...

  4. java获取properties配置文件值

    package me.ilt.Blog.util; import java.io.File; import java.io.FileInputStream; import java.io.IOExce ...

  5. 1.php开发环境安装

    1.安装环境 在链接https://sourceforge.net/projects/xampp/files/下载集成开发环境,此集成了web服务器.php开发.mysql数据库.傻瓜式安装step ...

  6. python multiprocessing.Process

    在使用Kafka-python时自己写的一个bug 我在一个进程的__init__中初始化了一个producer,但是一直不好用 但是在函数里直接new一个就好用了 why? 需要说明的是produc ...

  7. solr 的 field, copyfield ,dynamic field

    Field: Field就是一个字段,定义一个Field很简单: <field name="price" type="sfloat" indexed=&q ...

  8. Python学习_13_继承和元类

    继承 继承的含义就是子类继承父类的命名空间,子类中可以调用父类的属性和方法,由于命名空间的查找方式,当子类中定义和父类同名属性或者方法时,子类的实例调用的是子类中的属性,而不是父类,这就形成了pyth ...

  9. 在ssh框架中service,action,jsp,formbeam,dao的调用顺序

    本文来自:http://blog.csdn.net/w_basketboy24/article/details/8642846 jsp发起请求. actionform封装请求参数. action接受请 ...

  10. winform socket编程之TCPListener

    运行结果: 服务端代码 using System; using System.Collections.Generic; using System.ComponentModel; using Syste ...