AcWing
  • 首页
  • 题库
  • 题解
  • 分享
  • 问答
  • 活动
  • 应用
  • 吐槽
  • 登录/注册

AcWing 3133. 串珠子

作者: 作者的头像   Protein ,  2021-02-15 20:44:57 ,  阅读 10


1


#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; };
int main() {
    int m, n;
    while (cin >> m >> n, n || m) {
        int res = 0;
        for (int i = 0; i < n; i++)
            res += pow(m, GCD(n, i));
        if (n & 1) res += n * pow(m, (n + 1) / 2);
        else res += n / 2 * (pow(m, n / 2 + 1) + pow(m, n / 2));
        cout << res / n / 2 << endl;
    }
    return 0;
}

0 评论

你确定删除吗?

© 2018-2021 AcWing 版权所有  |  京ICP备17053197号-1
联系我们  |  常见问题
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标
请输入绑定的邮箱地址
请输入注册信息