C语言 | Leetcode C语言题解之第372题超级次方

题目:

题解:

cpp 复制代码
//计算a的b次方
int mypow(int a, int b){
    a = a % 1337; // 防止a过大超出规模
    int ret = 1;
    for(int i = 0; i < b; i++){
        ret *= a;
        ret = ret % 1337; //防止超出规模
    }
    return ret;
}
//整体计算
int superPow(int a, int* b, int bSize){
    if(a == 1) return 1;
    int sum = 1;
    for(int i = 0; i < bSize; i++){
        //由例子可知(x的10次方的次数)为(bSize-1),所以写在最开始,使得多出来的一次(循环次数为bSize)为计算1的十次方
        sum = mypow(sum, 10); 
        sum *= mypow(a, b[i]);
        sum = sum % 1337; //防止超出规模
    }


    return sum;
}
相关推荐
Zwawa15 小时前
屏幕不止一种:OLED、LCD1602字符屏、TFT/IPS图形屏和串口屏怎么用,这与TTY和PTY又有什么关系
c语言·单片机·嵌入式
Fruiticecake15 小时前
C 程序员速通现代 C++(一):lambda、std::function、移动语义与智能指针
c语言·c++
田甲15 小时前
做一款 Type-C 母座读卡器:GL3224 双卡方案实测
c语言·开发语言
文丑颜不良啊16 小时前
LeetCode2261~2280题目解析
java·leetcode
·present·20 小时前
CSAPP(lecture 13_02 Linking)
c语言·c++
文丑颜不良啊1 天前
LeetCode2241~2260题目解析
java·leetcode
文丑颜不良啊1 天前
LeetCode2321~2340题目解析
java·leetcode
wuyk5551 天前
Keil工具链-第05讲-启动文件与__main到底做了什么
c语言·stm32·单片机·嵌入式硬件·物联网
文丑颜不良啊2 天前
LeetCode2221~2240题目解析
java·leetcode
Navigator_Z2 天前
LeetCode //C - 1317. Convert Integer to the Sum of Two No-Zero Integers
c语言·算法·leetcode