僩僢僾儁乕僕偵栠傞    師偺C#偺僒儞僾儖傊    慜偺C#偺僒儞僾儖傊

C儅僈揹擼僋儔僽(戞055夞) 僇僂儞僩丒儚儞

栤戣

1񎎙丒丒丒N傑偱偺悢傪暲傋偰粋虙唫1偲偄偆悢帤偑偄偔偮偁傞偐傪悢偊傞
偮傑傝=1񎎙丒丒丒9傑偱偼悢帤偺1偼崌寁1屄=10偱2屄=11偱4屄偲偄偆傛偆偵悢偊傞傢偗偩

偝偰傑偱偺悢傪暲傋偨傜攷殏1偑偪傚偆偳N屄娷傑傟偰偄偨眰虃鎮萅偑慡晹偱偄偔偮偁傞偺偩傠偆偐
屄悢傪挷傋偰傎偟偄

嵟弶偵偁偰偼傑傞偺偼N=1偱偡傛O偺偨傔


僜乕僗

using System;

class Program
{
    const int Jyougen = 1999999999;

    static void Main()
    {
        var sw = System.Diagnostics.Stopwatch.StartNew();

        long SumCnt = 0;
        int AnsCnt = 0;

        int CurrCnt = 0;
        for (int I = 1; I <= Jyougen; I++) {
            if (I % 10 == 0) CurrCnt = DeriveOneCnt(I);
            else if (I % 10 == 1) CurrCnt++;
            else if (I % 10 == 2) CurrCnt--;

            SumCnt += CurrCnt;
            if (SumCnt == I) Console.WriteLine("{0}偱堦抳({1}屄栚)丅宱夁帪娫={2}",
                I, ++AnsCnt, sw.Elapsed);
        }
        Console.WriteLine("宱夁帪娫={0}", sw.Elapsed);
    }

    //pTarget.ToString().Count(X => X == '1')偺崅懍壔斉
    static int DeriveOneCnt(int pTarget)
    {
        int OneCnt = 0;
        do {
            int wkInt = pTarget % 10;
            if (wkInt % 10 == 1) OneCnt++;
        } while ((pTarget /= 10) > 0);
        return OneCnt;
    }
}


幚峴寢壥

徣棯
535000000偱堦抳(69屄栚)丅宱夁帪娫=00:00:34.1693382
535000001偱堦抳(70屄栚)丅宱夁帪娫=00:00:34.1738631
535199981偱堦抳(71屄栚)丅宱夁帪娫=00:00:34.1906055
535199982偱堦抳(72屄栚)丅宱夁帪娫=00:00:34.1950024
535199983偱堦抳(73屄栚)丅宱夁帪娫=00:00:34.1994795
535199984偱堦抳(74屄栚)丅宱夁帪娫=00:00:34.2035828
535199985偱堦抳(75屄栚)丅宱夁帪娫=00:00:34.2078021
535199986偱堦抳(76屄栚)丅宱夁帪娫=00:00:34.2122962
535199987偱堦抳(77屄栚)丅宱夁帪娫=00:00:34.2169194
535199988偱堦抳(78屄栚)丅宱夁帪娫=00:00:34.2212448
535199989偱堦抳(79屄栚)丅宱夁帪娫=00:00:34.2254373
535199990偱堦抳(80屄栚)丅宱夁帪娫=00:00:34.2296649
535200000偱堦抳(81屄栚)丅宱夁帪娫=00:00:34.2341632
535200001偱堦抳(82屄栚)丅宱夁帪娫=00:00:34.2383934
1111111110偱堦抳(83屄栚)丅宱夁帪娫=00:01:11.3469896
宱夁帪娫=00:02:11.1812856


夝愢

1寘偺悢偱偺1偺悢偼丄1屄
2寘偺悢偱偺1偺悢偼丄19屄(10偐傜19偺2寘栚偺暘偱10丄10偐傜90偺1寘栚偺暘偱9)
3寘偺悢偱偺1偺悢偼丄280屄
                    100偐傜199偺3寘栚偺暘偱100丄
                    100偐傜900偺2寘偺悢偺暘偱9*19 = 171
                    100偐傜900偺1寘偺悢偺暘偱9* 1 =   9
4寘偺悢偱偺1偺悢偼丄3700屄
                    1000偐傜1999偺4寘栚偺暘偱1000丄
                    1000偐傜9000偺3寘栚偺暘偱9*280 = 2520
                    1000偐傜9000偺2寘栚偺暘偱9* 19 =  171
                    1000偐傜9000偺1寘栚偺暘偱9*  1 =    9

1寘偺悢偺嵟戝抣偼丄9
1偺悢偼1 (椵寁偼1)
2寘偺悢偺嵟戝抣偼丄99
1偺悢偼19 (椵寁偼20)
3寘偺悢偺嵟戝抣偼丄999
1偺悢偼280 (椵寁偼300)
4寘偺悢偺嵟戝抣偼丄9999
1偺悢偼3700 (椵寁偼4000)
5寘偺悢偺嵟戝抣偼丄 99999
1偺悢偼46000 (椵寁偼50000)
6寘偺悢偺嵟戝抣偼丄  999999
1偺悢偼550000 (椵寁偼600000)
7寘偺悢偺嵟戝抣偼丄   9999999
1偺悢偼6400000 (椵寁偼7000000)
8寘偺悢偺嵟戝抣偼丄    99999999
1偺悢偼73000000 (椵寁偼80000000)
9寘偺悢偺嵟戝抣偼丄     999999999
1偺悢偼820000000 (椵寁偼900000000)
10寘偺悢偺嵟戝抣偼丄      9999999999   仼 偙偙偵拲栚両両両
1偺悢偼9100000000 (椵寁偼10000000000)  仼 偙偙偵拲栚両両両
11寘偺悢偺嵟戝抣偼丄        99999999999
1偺悢偼100000000000 (椵寁偼110000000000)
12寘偺悢偺嵟戝抣偼丄         999999999999
1偺悢偼1090000000000 (椵寁偼1200000000000)
13寘偺悢偺嵟戝抣偼丄          9999999999999
1偺悢偼11800000000000 (椵寁偼13000000000000)
14寘偺悢偺嵟戝抣偼丄           99999999999999
1偺悢偼127000000000000 (椵寁偼140000000000000)
15寘偺悢偺嵟戝抣偼丄            999999999999999
1偺悢偼1360000000000000 (椵寁偼1500000000000000)

1偺悢偼丄奺寘偱嵟忋埵寘偑1偺帪偑嵟傕憹壛悢偑懡偔
嵟忋埵寘偑2偐傜9偱憹壛悢偑堦掕側偺偼柧傜偐偱偡丅

10寘偺嵟戝抣偺9999999999偱1偺悢偺椵寁偑丄偦偺悢偺抣傪挻偊丄11寘埲崀傕摨條偱偁傞偙偲丅

10寘栚偱偼丄嵟忋埵寘偑1偺帪偵丄偦偺悢偺抣傪挻偊丄
埲屻丄嵟忋埵寘偑2偐傜9偱偺帪偵偼丄1偺悢偺椵寁偑丄偦偺悢偺抣傪挻偊傞偙偲偼側偄丅

偲摫偄偰丄忋尷傪1999999999偲偟偰傑偡丅