B. New Skateboard
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
个位十位分情况讨论
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
char a[];
int main()
{
scanf("%s",&a);
ll ans=;
int len=strlen(a);
int k=(int)a[]-;
if(k%==) ans++;
for(int i=;i<len;i++)
{
k=(int)a[i]-;
if(k%==) ans++;
int s=(int)a[i-]-;
if((s*+k)%==) ans+=i;
}
printf("%I64d\n",ans);
return ;
}

Codefroces B. New Skateboard的更多相关文章

  1. Codefroces 628B New Skateboard(数位+思维)

    题目链接:http://codeforces.com/contest/628/problem/B 题目大意:给你一段数字串s(1?≤?|s|?≤?3·10^5),求该字符串有多少子串是4的倍数.解题思 ...

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

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

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

  4. CodeForces 628B New Skateboard

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

  5. CodeForces628-B.New Skateboard

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

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

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

  7. Codeforces 628 B.New Skateboard

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

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

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

  9. CodeForces 628B New Skateboard 思维

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

随机推荐

  1. 《剑指offer》变态跳台阶

    一.题目描述 一只青蛙一次可以跳上1级台阶,也可以跳上2级--它也可以跳上n级.求该青蛙跳上一个n级的台阶总共有多少种跳法. 二.输入描述 n级台阶 三.输出描述 一共有多少种不同的跳法 四.牛客网提 ...

  2. MySQL服务启动:某些服务在未由其他服务或程序使用时将自动停止

    这几天因为工作需求,需要把MySQL请出来,所以将尘封已久的MySQL进行启动.可是事与愿违,兴许是许久没有访问MySQL了,MySQL生气的不理我,并向外抛出一阵阵报错.1.其中一个是:Window ...

  3. file_get_contents 无法采集 https 网站

    <?php echo file_get_contents("https://www.baidu.com"); ?> 运行以上代码会报以下错误: 再运行一次去看看!

  4. git diff的文字说明

    -U<n>--unified=<n> Generate diffs with <n> lines of context instead of the usual t ...

  5. 常见bug分析

    变量类型不匹配,形参和实参类型不匹配,隐式类型转换,变量类型赋值不匹配, 工具不熟悉,导致逻辑错误,查看代码,测试驱动开发,完整的测试用例,覆盖所有分支, 变量超出范围,对于大的数据要特别注意, 工具 ...

  6. zabbix4.0 使用nginx前端安装

    注:环境需求:centos7 1.安装阿里云yum源: rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/4.1/rhel/7/x86_64/zabb ...

  7. subline 快捷键与功能解释

    选择类 Ctrl+D 选中光标所占的文本,继续操作则会选中下一个相同的文本. Alt+F3 选中文本按下快捷键,即可一次性选择全部的相同文本进行同时编辑.举个栗子:快速选中并更改所有相同的变量名.函数 ...

  8. unity SystemInfo类 获得电量battery

    我觉得用Unity 开发最爽的地方, 不是unity跨平台,而是用其他语言,要用很复杂的逻辑才能完成的功能,unity用一两句代码就能搞定 就比如说获取Android 系统的电量,不用发广播,不用申请 ...

  9. CJOI 05新年好 (最短路+枚举)

    CJOI 05新年好 (最短路+枚举) 重庆城里有n个车站,m条双向公路连接其中的某些车站.每两个车站最多用一条公路连接,从任何一个车站出发都可以经过一条或者多条公路到达其他车站,但不同的路径需要花费 ...

  10. HDU 4462 Scaring the Birds (暴力枚举DFS)

    题目链接:pid=4462">传送门 题意:一个n*n的区域,有m个位置是能够放稻草人的.其余都是玉米.对于每一个位置(x,y)所放稻草人都有个作用范围ri, 即abs(x-i)+ab ...