---
title: "从n到m中出现多少个1"
author: "Juliet"
date: "2008-04-16T15:41:14Z"
tags: ["F#"]
slug: "n-m-1"
draft: false
lastmod: "2008-04-16T15:41:14Z"
id: 183413
url: "https://juliet.iteye.com/blog/183413"
---

1. f(n, m): N到M中出现多少个1。

2. g(x): 1到x中出现多少个1。则f(n, m) = g(m) - g(n - 1)

3. h(x, y): x在y位上出现多少个1。g(x) = h(x, 1) + h(x, 2) .... h(x, n)

   **每10个数会在个位出现1个1、每100个数会在十位出现10个1...**

sample input: 2 200
sample output: 139
compute: g(200)=200/10*1 (个位上1的个数) 
         + 200/100*10    (十位上1的个数)
         + 100;          (百位上1的个数)
         - g(1)
         = 139

**4. 给定的n为x位的整数，那么g(n)=n*(x-1)/10
                                  + x位上1的个数**
compute: g(200)=200*2/10
               + 100
               - 1
               =139