LightOJ - 1282 - 先頭と末尾の(すぐに電源を引き継いで数学の能力、)

リンク:

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

質問の意味:

あなたは、2つの整数を与えている:nとkは、あなたのタスクは、最も重要な3つの数字を見つけることです、そしてNKの最下位3桁。

アイデア:

引き継ぐための3つの迅速な電源投入後、トップ3を検討します。
\(N ^ K \)のように表すことができる(\ * 10 ^ M \ ) 科学的表記法を使用して、すなわち。
対数の両側得た(K * log10の(N)\
= LOG10()+ M \) 小数部の次に、X = LOG10()であるK * log10の(N)。
= 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\n", r1, r2);
    }
    
    return 0;
}

おすすめ

転載: www.cnblogs.com/YDDDD/p/11846328.html