博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj1286
阅读量:7140 次
发布时间:2019-06-28

本文共 806 字,大约阅读时间需要 2 分钟。

题意:与2409类似,只是只能有3种颜色。

分析:详见2409,注意输入0的情况。

View Code
#include 
#include
#include
#include
#include
using namespace std;int n, m;int gcd(int a, int b){ b = b % a; while (b) { a = a % b; swap(a, b); } return a;}int main(){ //freopen("t.txt", "r", stdin); n = 3; while (scanf("%d", &m), ~m) { if (m == 0) { printf("0\n"); continue; } long long ans = 0; for (int i = 1; i <= m; i++) ans += pow(n, gcd(i, m)); if (m & 1) ans += m * pow(n, m / 2 + 1); else ans += m / 2 * pow(n, m / 2) + m / 2 * pow(n, m / 2 + 1); ans /= m * 2; printf("%lld\n", ans); } return 0;}

转载地址:http://ysmrl.baihongyu.com/

你可能感兴趣的文章