0
点赞
收藏
分享

微信扫一扫

杭电LCY-ACM算法入门习题(01-04)

非凡兔 2022-05-06 阅读 42
算法c++

人见人爱A^B(HDU 2035)

Problem Description

Input

Output

Sample Input

Sample Output

解题思路:快速幂模板题
AC代码

#include <iostream>

using namespace std;

int quick_power(int a,int n)
{
    int ans = 1;
    while (n)
    {
        if (n % 2) ans = ans * a % 1000;//指数是奇数
        a = a * a % 1000;//底数平方(数据范围大,一般在乘法的地方取模)
        n >>= 1;//指数减半
    }
    return ans;
}

int main()
{
    int a,b;
    while (cin >> a >> b)
    {
        if (a == 0 && b == 0) break;
        
        int res = quick_power(a,b);
        cout << res << endl;
    }
    return 0;
}

解方程(HDU 2899)

Problem Description

Input

Output

Sample Input

Sample Output

举报

相关推荐

0 条评论