zoukankan      html  css  js  c++  java
  • Codeforces Round #308 (Div. 2)B. Vanya and Books 数学

    B. Vanya and Books

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/552/problem/B

    Description

    Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the n books should be assigned with a number from 1 to n. Naturally, distinct books should be assigned distinct numbers.

    Vanya wants to know how many digits he will have to write down as he labels the books.

    Input

    The first line contains integer n (1 ≤ n ≤ 109) — the number of books in the library.

    Output

    Print the number of digits needed to number all the books.

    Sample Input

    13

    Sample Output

    17

    HINT

    题意

    要写n个数,然后问你一个写了多少个数字

    比如17这个数,就写了2个数字

    题解:

    数学题,每一位都是9*10^n个

    代码:

    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define test freopen("test.txt","r",stdin)  
    #define maxn 1000010
    #define mod 1000000007
    #define eps 1e-6
    const int inf=0x3f3f3f3f;
    const ll infll = 0x3f3f3f3f3f3f3f3fLL;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //**************************************************************************************
    
    int main()
    {  
        ll n=read();
        ll i=9;
        ll k=1;
        ll ans=0;
        while(n>=i)
        {
            n-=i;
            ans+=i*k;
            k++;
            i=i*10;
        }
        ans+=n*k;
        cout<<ans<<endl;
    }
  • 相关阅读:
    win10 激活
    window10 将程序的快捷方式加到右键"发送到"
    UML 类图基本了解
    php move_uploaded_file 上传的文件移动带中文文件名的的问题
    php 的 PHPExcel1.8.0 使用
    msyql 数据类型存储大小及数据范围
    MySQL数据库设计规范
    测试工具
    show tables 或者 show databases 结果太多如何再筛选
    ubuntu 16.04 周期定时任务 crontab 的 使用
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4588083.html
Copyright © 2011-2022 走看看