POJ 3286-how Many 0 ' s? (Combinatorial Math _ interval count)

Source: Internet
Author: User

How many 0 ' s?Time limit:MS Memory Limit:65536KB 64bit IO Format:%i64d &%i64u SubmitStatusPracticePOJ 3286Appoint Description:System Crawler (2015-04-18)

Description

A Benedict Monk No.16 writes down the decimal representations of all natural numbers between and including M and n, mn. How many 0 ' would he write down?

Input

Input consists of a sequence of lines. Each line contains the unsigned 32-bit integers m and n, mn. The last line of input have the value of m negative and this line should is processed.

Output

For each line of input print one line of output with one integer number giving the number of 0 ' s written down by the monk.

Sample Input

10 11100 2000 5001234567890 23456789010 4294967295-1-1

Sample Output

122929876543043825876150

Test instructions: How many zeros appear in an interval. and Poj 2282, almost.

#include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include < iostream> #include <sstream> #include <algorithm> #include <set> #include <queue> #include <stack> #include <map>using namespace std;typedef long long ll;const int inf=0x3f3f3f3f;const double pi= ACOs ( -1.0); #define Lson l,mid,rt<<1#define Rson mid+1,r,rt<<1|1ll b[12]={ 1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000,10000000000,100000000000};    ll Get_res (ll N) {int i;    LL left,m;    LL cnt=0;        for (i=1;i<12;i++) {left=n/b[i]-1;        CNT+=LEFT*B[I-1];        M= (N%b[i]-n%b[i-1])/b[i-1];        if (m>0) cnt+=b[i-1];        else if (m==0) cnt+=n%b[i-1]+1;    if (N<b[i]) break; } return CNT;}    int main () {LL n,m;        while (~scanf ("%lld%lld", &n,&m)) {if (n==-1&&m==-1) break;        if (n>m) swap (n,m); printf ("%lld\n", Get_res (m)-get_res (n-1)); } return 0;}


POJ 3286-how Many 0 ' s? (Combinatorial Math _ interval count)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.