已 知 两 个 正 整 数 n , p;
求 n 的 p 次 方。
(n <=1,000,000,000 ; p <=20,000)
93分 WA 或 TLE
#include //TLE 高 精 压 位 快 速 幂
using namespace std;
#define int long long
const int N=1e8,Q=8;
static int st[35], top;
int n,p;
struct node{
int a[66699]={0},l=1;
void init(int y){a[0]=y;l=1;}
inline void Put (int num, bool x) {
top = 0;
while (num) st[++top] = num % 10, num /= 10;
if(x) for (int i = 1; i <= 8 - top; ++ i) putchar ('0');
while (top) putchar (st[top] + '0'), --top;
return;
}
void print(){
Put(a[l-1], 0);
for(int i=l-2;i>=0;--i)
Put(a[i], 1);
return;
}
node operator * (node x) const{
node t=*this,id;
id.l=t.l+x.l-1;
for(int i=0;ifor(int j=0;jif(id.a[i+j]>=N){
id.a[i+j+1]+=id.a[i+j]/N;
id.a[i+j]%=N;
}
}
}
while(id.a[id.l]){
id.a[id.l+1]+=id.a[id.l]/N;
id.a[id.l++]%=N;
}
return id;
}
}q1,p1;
inline void power(int r,int t){
q1.init(1);p1.init(r);
while(t){
if(t&1) q1=q1*p1;
p1=p1*p1;
t>>=1;
}
return ;
}
static inline void write(__int128 x) {
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
}
static inline __int128 po(int a, int b){
__int128 res = 1;
while (b){
for (int i = 1; i <= b % 10; i++)
res = (res * a);
__int128 x = a * a ;
__int128 y = x * x ;
__int128 z = y * y ;
a= z * x ;
b /= 10;
}
return res;
}
signed main(){
scanf("%lld%lld",&n,&p);
power(n,p);
q1.print();
return 0;
}
#include //WA 高 精 乘
using namespace std;
#define ll long long
const long long M=1e9;
unsigned long long n,p;
unsigned long long a[1090010];
__int128 len;
inline void gc(){
__int128 ans=0;
for(register int i=1;i<=len;++i){
a[i]=a[i]*n+ans;
ans=a[i]/M;
a[i]%=M;
}
while(ans){
a[len+1]=ans;
ans/=M;
++len;
}
}
int main(){
scanf("%llu%llu",&n,&p);
len=(unsigned long long)(log10(n))+1;
a[1]=1;
for(int i=1;i<=p;++i) gc();
while(!a[len]&&len>1) --len;
for(int i=len;i>0;--i){
if(i==len) printf("%llu",a[i]);
else printf("%0*llu",9,a[i]);
}
return 0;
}
求个p的n次方,你为什么会有这么多代码,把无关的代码先删一删,把你关注的代码都调明白了再把那些一点一点的加上去,别一下什么都堆一起,没法调
@於黾 代码已经很精简了,但下面的 高精乘 只是参考。而且看清数据范围,不能那样简单写。(n的p次方)