1.题目链接。比较简单的一道组合问题,所有不是本原串的串的特点肯定都是一些长度为k并且循环了n/k次(k|n)的。所以显然,枚举因子计算不是本原串的串完事。记忆化一下完事。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = 2008;
#pragma warning(disable:4996)
map<ll, ll>mp;
ll qpow(ll a, ll b) {
ll res = 1;
while (b)
{
if (b & 1)res = res * a%mod;
a = a * a%mod;
b >>= 1;
}
return res;
}
const ll maxn = 1e6 + 100;
ll get(ll n)
{
if (n == 1)return 2;
if (mp[n])return mp[n];
ll sum = 0;
for (int i = 2; i*i <= n; i++)
{
if (n%i == 0)
{
sum = (sum + get(i)) % mod;
if (i*i != n)sum = (sum + get(n / i)) % mod;
}
}
ll ans = (qpow(2, n) - sum - 2 + mod) % mod;;
return mp[n]=ans;
}
int main()
{
ll n;
while (~scanf("%lld", &n))
{
mp.clear();
mp[1] = mp[2] = 2;
printf("%lld\n", get(n));
}
return 0;
}