• LightOJ 1282 Leading and Trailing (快速幂+fmod)


    求n^k的前三位以及后三位;
    后三位可用快速幂求解;
    求n^k的前三位:
    n可以写成10^a(a为小数)的形式。n^k=(10^a)^k,即10^(a*k),a*k可以写成x(整数)+y(小数)的形式;
    函数:fmod(x,1)可以求出x的小数部分,因此用fmod(a*k,1)即可求出y。

    #include <algorithm>
    #include <iostream>
    #include <cmath>
    #include <cstdio>
    #include <cstring>
    #include <map>
    using namespace std;
    typedef long long LL;
    const LL N = 1e6 + 10;
    const LL MOD = 1000;
    LL func(LL n, LL m)
    {
        LL sum = 1;
        while(m > 0) {
            if(m % 2)
                sum = (sum * n) % MOD;
            n = (n * n) % MOD;
            m /= 2;
        }
        return sum;
    }
    int main()
    {
        LL n, it = 1, i, m, k;
        cin >> n;
        while(n--) {
            scanf("%lld%lld", &m, &k);
            printf("Case %lld:", it++);
            LL ans = 100.0 * pow(10.0, fmod(k * log10(m * 1.0), 1));
            LL num = func(m, k);
            printf(" %03lld %03lld
    ", ans, num);
        }
        return 0;
    }
  • 相关阅读:
    matplotlib实例笔记
    matplotlib笔记3
    pandas之时间重采样笔记
    pandas之时间序列笔记
    pandas之数据IO笔记
    pandas之聚合运算
    pandas之分组计算笔记
    算术运算符合
    数据类型 概况 (字符串,列表)
    for 循环
  • 原文地址:https://www.cnblogs.com/yu0111/p/6739804.html
Copyright © 2020-2023  润新知