zoukankan      html  css  js  c++  java
  • LightOJ

    链接:

    https://vjudge.net/problem/LightOJ-1282

    题意:

    You are given two integers: n and k, your task is to find the most significant three digits, and least significant three digits of nk.

    思路:

    后三位快速幂取余,考虑前三位。
    (n^k)可以表示为(a*10^m)即使用科学计数法。
    对两边取对数得到(k*log10(n) = log10(a)+m)
    则x = log10(a)是k*log10(n)的小数部分。
    a = pow(10, x).就是科学计数法的前面部分。

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<math.h>
    #include<vector>
    #include<map>
    
    using namespace std;
    typedef long long LL;
    const int INF = 1e9;
    
    const int MAXN = 1e6+10;
    const int MOD = 1e9+7;
    
    LL n, k;
    
    LL PowMod(LL a, LL b)
    {
        LL res = 1;
        while(b)
        {
            if (b&1)
                res = res*a%1000;
            a = a*a%1000;
            b >>= 1;
        }
        return res;
    }
    
    int main()
    {
        int t, cnt = 0;
        scanf("%d", &t);
        while(t--)
        {
            printf("Case %d:", ++cnt);
            scanf("%lld%lld", &n, &k);
            double v = 1.0*k*log10(n);
            v -= (LL)v;
            LL r1 = (LL)(pow(10, v)*100);
            LL r2 = PowMod(n, k);
            printf(" %lld %03lld
    ", r1, r2);
        }
        
        return 0;
    }
    
  • 相关阅读:
    5.3二叉树的运算
    hadoop namenode切换
    org.apache.hadoop.security.AccessControlException
    Hive中的日志
    命令大全详解
    python深浅copy
    awk命令
    head&tail命令
    cut命令
    理解inode
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11846328.html
Copyright © 2011-2022 走看看