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, m ≤ n. 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, m ≤ n. 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)