列表

详情


NC24825. [USACO 2009 Feb B]Cruel Math Teacher, I

描述

Bessie has returned to 8th grade in order to finish her diploma. Her cruel math teacher wants the students to calculate "powers of integers". An integer power is the resultant integer when some number N (1 <= N <= 2,000,000,000) is multiplied by itself over and over P times (1 <= P <= 100,000).
By way of example, 2 to the power 3 = 2 * 2 * 2 (three times) = 8. Similarly, 123456 to the power 88 = 123456 * 123456 * ... * 123456 (88 times) =  1129987770413559019467963153621658978635389622595924947762339599136126 3387265547320084192414348663697499847610072677686227073640285420809119 1376617325522768826696494392126983220396307144829544079751988205731569 1498433718478969549886325738202371569900214092289842856905719188890170 0772424218248094640290736200969188059104939824466416330655204270246371 3699112106518584413775333247720509274637795508338904731884172716714194 40898407102819460020873199616 when printed 70 digits per line.
Write a program to calculate the Pth power of an integer N. The answer is guaranteed to be no longer than 15,000 digits. Print your answer 70 digits per line (except the last line which might be shorter). Do not print leading zeroes, of course.

输入描述

* Line 1: Two space-separated integers: N and P

输出描述

* Lines 1..?: A single integer that is the result of the calculation. Print 70 digits per line except potentially for the last line, which might be shorter.

示例1

输入:

2 15

输出:

32768

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

Java 解法, 执行用时: 46ms, 内存消耗: 12480K, 提交时间: 2021-10-14 20:37:10

import java.util.*;
import java.math.*;
import java.text.*;
public class Main{
    public static void main(String args[]){
       Scanner cin= new Scanner(System.in);
        BigInteger a;
        int b,c;
       a = cin.nextBigInteger();
        b = cin.nextInt();
        a = a.pow(b);
        System.out.println(a);
     } 
}

Python3(3.5.2) 解法, 执行用时: 30ms, 内存消耗: 6388K, 提交时间: 2019-09-26 10:39:17

n,m=map(int,input().split())
print(n**m)

上一题