zoukankan      html  css  js  c++  java
  • lightoj1281快速幂+数学知识

    https://vjudge.net/contest/70017#problem/E

    后半部分快速幂就能求出来,要注意03lld不然001是输出错误为1.前半部分用log10()

    对于给定的一个数n,它可以写成10^a,其中这个a为浮点数,则n^k=(10^a)^k=10^a*k=(10^x)*(10^y);其中x,y分别是a*k的整数部分和小数部分,对于t=n^k这个数,它的位数由(10^x)决定,它的位数上的值则有(10^y)决定,因此我们要求t的前三位,只需要将10^y求出,在乘以100,就得到了它的前三位。

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<cstring>
    #include<algorithm>
    #define ll long long
    using namespace std;
    const int maxn=100010;
    ll quick_mul(ll a,ll b)
    {
        ll ans=1;
        while(b){
            if(b&1!=0)ans=(ans%1000)*(a%1000);
            a=(a%1000)*(a%1000);
            b/=2;
        }
        return ans%1000;
    }
    ll solve(ll a,ll b)
    {
        double ans=b*log10(a);
        ans=ans-floor(ans);
        ans=pow(10,ans)*100;
        return (ll)ans;
    }
    int main()
    {
        int t,cas=0;
        scanf("%d",&t);
        while(t--){
            ll n,k;
            scanf("%lld%lld",&n,&k);
            printf("Case %d: %lld %03lld
    ",++cas,solve(n,k),quick_mul(n,k));
        }
        return 0;
    }
  • 相关阅读:
    spring cloud项目搭建
    获取iframe的window对象
    数学杂谈 #7
    [AGC023D] Go Home
    JOISC 2021 部分题解
    [NOI2017]泳池
    [NOI2016] 循环之美
    [NOI2016] 优秀的拆分
    [LG P3676]小清新数据结构题
    [ARC113F]Social Distance
  • 原文地址:https://www.cnblogs.com/acjiumeng/p/6505930.html
Copyright © 2011-2022 走看看