http://acm.hdu.edu.cn/showproblem.php?pid=2197
思路:可以用0和1的总串减去非本原子串,而非本原子串是由n的因子组成。
代码:
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <string>
#include <map>
#include <cmath>
using namespace std;
const int N=2008;
map<int,int>mp;
long long int n;
int poww(int a,int b)
{
long long int m=1,n=a%N;
while(b)
{
if(b&1)m=m*n%N;
n=n*n%N;
b>>=1;
}
return m;
}
int ff(long long int x)
{
if(mp[x]!=0)return mp[x];
if(x==1) return mp[x]=2;
long long int ans=poww(2,x);
ans=(ans-2)%N;
for(int i=2;i*i<=x;i++)
{
if(x%i!=0)continue;
if(i*i==x)
{
ans=(ans-ff(i))%N;
continue;
}
else
{
ans=(ans-ff(i))%N;
ans=(ans-ff(x/i))%N;
}
}
return mp[x]=(ans+N)%N;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
printf("%d\n",ff(n));
}
return 0;
}