• 2017ACM暑期多校联合训练


    题目链接

    Problem Description
    There is a youngster known for amateur propositions concerning several mathematical hard problems.

    Nowadays, he is preparing a thought-provoking problem on a specific type of supercomputer which has ability to support calculations of integers between 0 and (2m−1) (inclusive).

    As a young man born with ten fingers, he loves the powers of 10 so much, which results in his eccentricity that he always ranges integers he would like to use from 1 to 10k (inclusive).

    For the sake of processing, all integers he would use possibly in this interesting problem ought to be as computable as this supercomputer could.

    Given the positive integer m, your task is to determine maximum possible integer k that is suitable for the specific supercomputer.

    Input
    The input contains multiple test cases. Each test case in one line contains only one positive integer m, satisfying 1≤m≤105.

    Output
    For each test case, output "Case #x: y" in one line (without quotes), where x indicates the case number starting from 1 and y denotes the answer of corresponding case.

    Sample Input
    1
    64

    Sample Output
    Case #1: 0
    Case #2: 19

    分析:
    其实就是一个公式对应的求解过程,在m已知的情况下求k,其关系式为:
    10^k=2^m-1

    看到这个式子首先想到用对数公式来化简,但是因为等式右面的式子是2^m-1这样的话是没有办法化简得,有没有办法解决呢?
    我们注意到一点就是不管2的几次幂,其最后的一位数字都是在2,4,6,8这几个数字中循环,所以尽管将其结果后面减去的哪个1不考虑也不会影响其十位数的大小,这样的话转换成10的幂次也不会改变。

    关系式就变成10^k=2^m两边同时取以10为底的对数然后将k表示出来就是:k=m*log10(2);

    #include<iostream>
    #include <cmath>
    #include <stdio.h>
    using namespace std;
    int main()
    {
       int m,Case=0;
       while(~scanf("%d",&m))
       {
           Case++;
            int k=(int)(m*log10(2));
            printf("Case #%d: %d
    ", Case, k);
       }
        return 0;
    }
    
  • 相关阅读:
    【剑指Offer】跳台阶&变态跳台阶
    【剑指Offer】替换空格
    【剑指Offer】二维数组中的查找
    【Leetcode】2. Add Two Numbers 两数相加
    HTML学习笔记(一)HTML的一些概念区别
    C#项目中一些文件类型说明
    数据结构初步归纳(一)概念、线性表以及队列和栈
    线程相关概念
    程序开发方法论
    C#集合类型
  • 原文地址:https://www.cnblogs.com/cmmdc/p/7238456.html
Copyright © 2020-2023  润新知