int main(){
int T;
scanf(“%d”,&T);
for(int i =0;i<T;i++){
int n ,m ;
scanf(“%d %d”,&n,&m);
int nums[100000] = {1};
cnt = 0;
for(int i =0;i<m;i++){
mulByArr(nums,n);
}
import java.io.*;
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
BigInteger a;
int b;
// TODO Auto-generated method stub
Scanner cin = new Scanner (System.in);
int t;
t = cin.nextInt();
for (int i = 0;i<t;i++) {
a = cin.nextBigInteger();
b = cin.nextInt();
System.out.println(“case #”+i+”:”);
System.out.println(a.pow(b));
// System.out.println(a.remainder(b));
}
}
}
高精度乘法,我简单封装了一下
include
using namespace std;
typedef vector BIG;
int T,n;
BIG create(int aa)
{
BIG ret;
ret.push_back(aa);
while(ret[ret.size()-1]>=10)
{
int Top=ret.size()-1;
ret.push_back(ret[Top]/10);
ret[Top]%=10;
}
return ret;
}
BIG operator(const BIG& aa,int bb)
{
BIG ret;
ret.assign(aa.begin(),aa.end());
for(int i=0;i=10) { int Top=ret.size()-1; ret.push_back(ret[Top]/10); ret[Top]%=10; } while(ret[ret.size()-1]==0) ret.pop_back(); return ret; } void print(const BIG& aa) { for(int i=aa.size()-1;i>=0;i–) cout<>a>>b;
if(b==0) cout<<1<<endl;
else
{
BIG tmp=create(a);
for(int i=1;i<b;i++) tmp=tmpa;
print(tmp);
cout<>T;
for(int step=0;step<T;step++)
{
printf(“case #%d:\n”,step);
solve();
}
return 0;
}
python来凑
a=eval(input())
c=0
while a>0:
b=input().split()
print(‘{}{}{}’.format(‘case #’,c,’:’))
c=c+1
print(int(b[0])**int(b[1]))
a=a-1
本菜鸟的另一种垃圾算法
先将每一位进行无进位乘法,再处理每一位的进位
include
int cnt = 0;
void mulByArr(int nums[], int val){
int temp;
for(int k = cnt;k>=0;k–){
nums[k] *=val;//无进位乘
}
if(cnt>=1){ //对后n-1位进行进位
for(int i = cnt;i>=1;i–){
if(nums[i]>=10){
temp = nums[i]/10;
nums[i]%=10;
nums[i-1]+=temp;
}
}
}
if(nums[0]>=10){//判断首位是否十进制溢出,如果是则把后n-1位统一向后移一位,然后处理首位溢出
for(int j = cnt;j>=1;j–){
nums[j+1] = nums[j];
}
nums[1] = nums[0]%10;
nums[0] = nums[0]/10;
cnt++;
}
}
int main(){
int T;
scanf(“%d”,&T);
for(int i =0;i<T;i++){
int n ,m ;
scanf(“%d %d”,&n,&m);
int nums[100000] = {1};
cnt = 0;
for(int i =0;i<m;i++){
mulByArr(nums,n);
}
}
高精度乘法,我简单封装了一下
楼主写了好长。。膜
C语言版:
include
void solve(int x)
{
int a,b;
scanf(“%d %d”,&a,&b);
int s[100]={0};
s[0]=1;
int i,k,flag=0;
for(i=0;i<b;++i)
{
for(k=0;k<100;++k)
{
s[k]=s[k]*a;
}
for(k=0;k<100;++k)
{ s[k]=s[k]+flag;
flag=0;
if(s[k]>=10)
{
flag=s[k]/10;
s[k]=s[k]%10;
}
else
{
flag=0;
}
}
}
}
int main()
{
int T,i;
scanf(“%d”,&T);
getchar();
for(i=0;i<T;++i)
{
solve(i);
}
}
[em:01]
import java.io.*;
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
BigInteger a;
int b;
// TODO Auto-generated method stub
Scanner cin = new Scanner (System.in);
int t;
t = cin.nextInt();
for (int i = 0;i<t;i++) {
a = cin.nextBigInteger();
b = cin.nextInt();
System.out.println(“case #”+i+”:”);
System.out.println(a.pow(b));
// System.out.println(a.remainder(b));
}
}
}