3417. 求幂

Fifnmar

c++ 的 unsigned long long 轻松水过……

using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    unsigned a, b;
    cin >> a >> b;
    unsigned long long ans = a;
    while (--b)
        ans *= a;
    cout << ans;
}
Brown897
#include <bits/stdc++.h>
#define LL long long
using namespace std;

LL binary(LL a,LL b){
    if(b==0) return 1;
    else if(b%2==0) return binary(a,b/2)*binary(a,b/2);
    else return binary(a,b-1)*a;
}


int main(){
    LL a,b;
    cin>>a>>b;
    cout<<binary(a,b);
    return 0;
}
Luckywei233

include

using namespace std;
string add(string tar, string ad) {
int flag = 0;
string temp = ad;
int x = 1;
for (int i = tar.length()-1; i >= 0; i–) {
int a = tar.at(i) + ad.at(ad.length()-x)+flag- 96;
temp.at(ad.length() - x) = a % 10+48;
if (a >= 10) {
flag = a / 10;
}
else flag = 0;
x++;
}
for (int i = ad.length() - tar.length()-1; i >= 0; i–) {
int a = ad.at(i) + flag-48;
temp.at(i) = a % 10 + 48;
if (a >= 10) {
flag = a / 10;
}
else {
flag = 0;
}
}
if(flag > 0) {
temp.append(“0”);
for (int i = temp.length() - 1; i >= 1; i–) {
temp.at(i) = temp.at(i - 1);
}
temp.at(0) = flag + 48;
}
return temp;
}
string times(string tar,int n) {
int flag = 0;
for (int i = tar.length() - 1; i >= 0; i–) {
int a = ((tar.at(i) - 48) * n)+flag;
tar.at(i) = a % 10 + 48;
if (a >= 10) {
flag = a / 10;
}
else flag = 0;
}if (flag > 0) {
tar.append(“0”);
for (int i = tar.length() - 1; i >= 1; i–) {
tar.at(i) = tar.at(i - 1);
}
tar.at(0) = flag + 48;
}
return tar;
}
string strtimes(string tar,string n){
int loc = 0;
string sum;
for(int i = n.length()- 1; i >= 0; i–) {
string temp = times(tar, n.at(i) - 48);
for (int i = 1; i <= loc; i++) {
temp.append(“0”);
}
loc++;
sum = add(sum,temp);
}
return sum;
}
int main() {
string i;
int n;
std::cin >> i;
std::cin >> n;
string temp = i;
for (int a = 1; a < n; a++) {
temp = strtimes(temp, i);
}cout << temp;
return 0;
}

你当前正在回复 博客/题目
存在问题!