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 usegets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/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 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的倍数,所以只用判断个位和十位就好;

AC代码:

#include <bits/stdc++.h>
using namespace std;
const int N=1e5+4;
char str[3*N];
int a,b;
int main()
{
scanf("%s",str);
int len=strlen(str);
long long ans=0;
a=str[0]-'0';
if(a%4==0)ans++;
for(int i=1;i<len;i++)
{
a=str[i]-'0';
if(a%2==0)
{
if(a%4==0)
ans++;
b=str[i-1]-'0';
if((b*10+a)%4==0)
{
ans+=i;
}
}
}
cout<<ans<<"\n";
return 0;
}

codeforces 628B B. New Skateboard (数论)的更多相关文章

  1. [CodeForces - 1225D]Power Products 【数论】 【分解质因数】

    [CodeForces - 1225D]Power Products [数论] [分解质因数] 标签:题解 codeforces题解 数论 题目描述 Time limit 2000 ms Memory ...

  2. Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论

    Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论 题意 给你一段数,然后小明去猜某一区间内的gcd,这里不一定是准确值,如果在这个区间内改变 ...

  3. CodeForces 628B New Skateboard

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

  4. CodeForces 628B New Skateboard 思维

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

  5. Codeforces 55D (数位DP+离散化+数论)

    题目链接: http://poj.org/problem?id=2117 题目大意:统计一个范围内数的个数,要求该数能被各位上的数整除.范围2^64. 解题思路: 一开始SB地开了10维数组记录情况. ...

  6. Codeforces 833A The Meaningless Game - 数论 - 牛顿迭代法 - 二分法

    Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting. T ...

  7. Codeforces 837E Vasya's Function - 数论

    Vasya is studying number theory. He has denoted a function f(a, b) such that: f(a, 0) = 0; f(a, b) = ...

  8. Codeforces 837D Round Subset - 动态规划 - 数论

    Let's call the roundness of the number the number of zeros to which it ends. You have an array of n ...

  9. Codeforces 955C - Sad powers(数论 + 二分)

    链接: http://codeforces.com/problemset/problem/955/C 题意: Q次询问(1≤Q≤1e5),每次询问给出两个整数L, R(1≤L≤R≤1e18),求所有符 ...

随机推荐

  1. ubuntu 1204 安装mysql

    检測本机是否有安装mysql sudo netstat -tap | grep mysql 运行上面的命令之后.看到 mysq 的socket 处于监听状态,说明有成功安装. 安装mysql sudo ...

  2. js中return;return true return false 的区别

    return 定义: return 语句会 终止函数的执行 并 返回函数的值. 注意这两个: 1.终止函数的执行 2.返回函数的值 返回函数的值这里就不过多叙述了,就是 return 变量 先看下面的 ...

  3. ajax Form提交与Payload提交

    后端处理前端提交的数据时,既可以使用Form解析,也可以使用JSON解析Payload字符串. Form解析可以直接从Request对象中获取请求参数,这样对象转换与处理相对容易,但在大片JSON数据 ...

  4. poj 2524 Ubiquitous Religions(并查集)

    Ubiquitous Religions Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 23168   Accepted:  ...

  5. [Android] 拍照、截图、保存并显示在ImageView控件中

    近期在做Android的项目,当中部分涉及到图像处理的内容.这里先讲述怎样调用Camera应用程序进行拍照,并截图和保存显示在ImageView控件中以及遇到的困难和解决方法.     PS:作者购买 ...

  6. 串 2016Vijos省选集训 day3[AC自动机]

    1.串(string.c/.cpp/.pas) 限时1s,内存限制256MB,20个测试点 [题目描述] 兔子们在玩字符串的游戏.首先,它们拿出了一个字符串集合S,然后它们定义一个字符串为“好”的,当 ...

  7. 【BZOJ2844】albus就是要第一个出场 高斯消元求线性基

    [BZOJ2844]albus就是要第一个出场 Description 已知一个长度为n的正整数序列A(下标从1开始), 令 S = { x | 1 <= x <= n }, S 的幂集2 ...

  8. 论JavaWeb前后端分离放弃jsp

    1.静态资源使用Nginx反向代理Tomcat,Tomcat挂了网站仍可访问.2.静态与后端服务器分离,提升性能.3.大并发情况下,可同时扩展前后端服务器.4.接口可复用至App相关服务.5.网站热部 ...

  9. 九度OJ 1187:最小年龄的3个职工 (排序)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2291 解决:936 题目描述: 职工有职工号,姓名,年龄.输入n个职工的信息,找出3个年龄最小的职工打印出来. 输入: 输入第一行包括1个 ...

  10. 【python】-- RabbitMQ 安装、基本示例、轮询机制

    RabbitMQ MQ全称为Message Queue, 是一种分布式应用程序的的通信方法,它是消费-生产者模型的一个典型的代表,producer往消息队列中不断写入消息,而另一端consumer则可 ...