旋转加翻转
#include <iostream>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define maxn 1200
#define eps 1e-8
int gcd(int n,int m)
{
if (m == 0) {
return n;
}
return gcd(m,n%m);
}
int c,s;
int main()
{
while (cin>>c>>s&&c&&s) {
long long ans = 0;
for (int i = 1; i<=s; i++) {
ans += pow(c, gcd(s, i));
}
if (s&1) {
ans += s*pow(c, s/2+1);
}
else
ans += s/2*pow(c, (s+2)/2)+s/2*pow(c, s/2);
ans /= s*2;
cout<<ans<<endl;
}
return 0;
}

被折叠的 条评论
为什么被折叠?



