Given two integers l and R, all the approximate numbers of X are written down for all x that satisfies 1≤l≤x≤r≤10^9. For each number written down, keep only the highest digit of that digital. 1~9 the number of occurrences of each digit.

Source: Internet
Author: User

Explanation: Take 1 as an example to enumerate 1-1,10-19,100-199, .... Every time from the right boundary to find the quotient K, according to the formula to find the nearest point to the left to make the quotient for k+1, if d=1, then the left point does not exist K+1,ans can add k*d distance, and then skip the distance.


Code:

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h >
#include <queue>
using namespace std;
typedef long long LL;
const int MX = 1E5+10;
int n,m,len,mid;
ll Cnt[11];
Char str[15];
ll get_sum (int l,int r,int x) {
	ll ans = 0;
	r = min (r,x); 
	int k = X/r,mod = x%r;
	while (1) {
		int d = (r-mod)/(k+1);
		if (d* (k+1) <r-mod) d++;
		if (r-d<l) break;
		Ans + = k*d;
		MoD = (k*d+mod)% (r-d);
		R = r-d;
		K = d==1? x/r:k+1;
	}
	ans+= (r-l+1) *k;
	return ans;
}
void work (Int. X,int v) {for
	(int i=1;i<10;i++) {
		int rode = 1;
		while (1ll*i*rode<=x) {
			int rr = i*rode+rode-1;
			Cnt[i] + = V*get_sum (i*rode,rr,x);
			rode*=10	
;
}}} int main () {while
	(~scanf ("%d%d", &n,&m)) {
		memset (cnt,0,sizeof (CNT));
		Work (m,1); 
		Work (n-1,-1);
		for (int i=1;i<10;i++)
		printf ("%lld\n", Cnt[i]);
	}
	return 0;
}


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.