zoukankan      html  css  js  c++  java
  • LightOJ1282 Leading and Trailing

     1 /*
     2  LightOJ1282 Leading and Trailing
     3  http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1282
     4  数论 fmod
     5  fmod题。
     6  求n^k的前三位
     7  n可以写成10^a(a为小数)的形式。
     8  因此原式=10^(ak).
     9  而ak可以写成x+y,其中x为ak的整数部分,y为ak的小数部分
    10  所以x决定了位数,y决定了值
    11  因此求出y即可。
    12  而n=10^a => a=log10(n)
    13  fmod(x,1)可以求出x的小数部分
    14  因此用fmod(ak,1)即可求出y
    15  */
    16 #include <cstdio>
    17 #include <algorithm>
    18 #include <cstring>
    19 #include <cmath>
    20 #include <vector>
    21 #include <queue>
    22 #include <iostream>
    23 #include <map>
    24 #include <set>
    25 //#define test
    26 using namespace std;
    27 const int Nmax=1e6+7;
    28 const long long mod=1000;
    29 long long qpow(long long base,long long n)
    30 {
    31     base%=mod;
    32     long long ans=1LL;
    33     while(n>0)
    34     {
    35         if(n&1)
    36             ans=(ans*base)%mod;
    37         base=(base*base)%mod;
    38         n>>=1;
    39     }
    40     ans=ans%mod;
    41     return ans;
    42 }
    43 int main()
    44 {
    45     #ifdef test
    46     #endif
    47     int t;
    48     scanf("%d",&t);
    49     t=0;
    50     long long n,k;
    51     while(scanf("%lld%lld",&n,&k)==2)
    52     {
    53         t++;
    54         double x=pow(10.0,fmod(k*log10(1.0*n),1)); 
    55         x=x*100.0;
    56         printf("Case %d: %d %03lld
    ",t,(int)x,qpow(n,k));
    57     }
    58     return 0;
    59 }
  • 相关阅读:
    《乘法运算定律》
    pytest(三十九)--内置request读取项目的根目录 rootdir
    《乘除法意义及各部分关系》
    《比例尺》
    《百分数》
    《8的乘法口诀》
    《1升有多少》
    ant-design-vue 上传图片组件
    ant-design-vue快速搭建
    js实现无缝滚动
  • 原文地址:https://www.cnblogs.com/BBBob/p/6710663.html
Copyright © 2011-2022 走看看