zoukankan      html  css  js  c++  java
  • NOJ1659 求值 log10取对+floor

     

    • 问题描述
    • 给你三个数a,b,c,求a的b次的前c位数(不够c位输出全部即可)
    • 输入
    • 输入数据有多组,每组占一行,有三个整数,之间有空格。(0<a,b<2147483648,0<c<10)
    • 输出
    • 对于每组输入数据,输出一行.
    • 样例输入
    • 55 20 6
      10 5 2
    • 样例输出
    • 641584
      10

    想法:看题目就知道无法使用数组,这就要想到使用对数来使数据以指数形式储存,因为c是小于10,这个办法显然可行。具体思路上,a^b=x,那么设t=b*log10(a),于是,t的整数部分即为10的n次方相当于x/10^n,而t的小数部分就可以拿来控制位数,当要求c位时乘以10^(c-1)即可。核心代码 int(pow(10, x)*pow(10, c-1))。注意类型转换,和精度问题。

     1 #include <stdio.h>
     2 #include <iostream>
     3 #include <algorithm>
     4 #include <math.h>
     5 #include <string.h>
     6 using namespace std;
     7 
     8 int main()
     9 {
    10     double a, b, c;
    11     double t, x;
    12     while(~scanf("%lf%lf%lf", &a, &b, &c))
    13     {
    14         t = b*log10(a);
    15         if(t >= c*1.000000 )
    16         {
    17             x=t-floor(t);
    18             cout << int(pow(10, x)*pow(10, c-1)) << endl;
    19         }
    20         else cout << pow(a, b) << endl;
    21     }
    22 }
  • 相关阅读:
    前置++和后置++的区别
    snmp数据包分析
    [codeforces538E]Demiurges Play Again
    [codeforces538D]Weird Chess
    [BZOJ3772]精神污染
    [BZOJ4026]dC Loves Number Theory
    [BZOJ1878][SDOI2009]HH的项链
    [BZOJ3658]Jabberwocky
    [BZOJ3932][CQOI2015]任务查询系统
    [BZOJ3551][ONTAK2010]Peaks加强版
  • 原文地址:https://www.cnblogs.com/Yumesenya/p/5347634.html
Copyright © 2011-2022 走看看