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. Yaml 的python 应用

    1.安装yaml的python包 2.准备yaml的数据 3.yaml.load 解析yaml 3.生产yaml

  2. LINQ to Tree - A Generic Technique for Querying Tree-like Structures,包含遍历WPF VisualTree

    https://www.codeproject.com/Articles/62397/LINQ-to-Tree-A-Generic-Technique-for-Querying-Tree#generi ...

  3. java getResourcesAsStream()如何获取WEB-INF下的文件流

    getResourcesAsStream()来读取.properties文件,但是getResourcesAsStream()仅在java项目时能获取根目录的文件: 在web项目中,getResour ...

  4. jquery基础研究学习【效果】

    ---------------------------------分割线-------------------------------------- 2017年6月7日18:16:35Query 效果 ...

  5. Cocos2d-x中使用第三方so库

    项目中假设使用到第三方的SDK,大多数是以.so动态共享库的文件打包给我们使用.怎样使用他们,见以下分析. 1.获得库文件 假如我们得到的库文件是libxxx.so(注:关于.so文件的命名方式,可百 ...

  6. 装服务器,测试数据库,简单的maven命令

    [说明]今天总体回顾一下:大概是早上装服务器,下午测试数据库,晚上了解简单的maven命令 一:今日完成 1)在远程服务器的tomcat 设置好管理员的登录账号 2)登录tomcat 的项目管理 查看 ...

  7. ibatis实现Iterate的使用 (转)

    <iterate         property="" /*可选,              从传入的参数集合中使用属性名去获取值,              这个必须是一 ...

  8. Django 认证系统 cookie & session & auth模块

    概念 cookie不属于http协议范围,由于http协议无法保持状态,但实际情况,我们却又需要“保持状态”,因此cookie就是在这样一个场景下诞生. cookie的工作原理是:由服务器产生内容,浏 ...

  9. Django继承HTML模板

    Django在渲染模板的过程中可以实现模板样式的继承,以减少重复的代码 1.extend继承 模板.html: 模板内容 {{% block name1 %}} {{% enfblock %}} #n ...

  10. Windows下重置MySQL密码(最开始是因为Access denied for user 'root'@'localhost'这个原因,无法登陆 'root'@'localhost')

    本人使用的MySQL5.5,其他版本未测试过. 方法一: 更改密码: mysql -u root -p Enter password:*** mysql>use mysql; 选择数据库 Dat ...