本原串
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 517 Accepted Submission(s): 176
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
int n;
const int mod = 2008;
int hash[1001000];
int pow(int a,int b)
{
int sum = 1;
while(b > 1)
{
if(b % 2 == 1)
{
sum *= a;b --;
sum %= mod;
}
a = (a * a) % mod;b /= 2;
}
sum = (sum * a) % mod;
return sum;
} int get(int n)
{
int sum = 0;
if(n == 1)
return 2;
for(int i = 2;i * i <= n;++ i)
{
if(n % i == 0)
{
if(i >= 1000000)
sum = (sum + get(i)) % mod;
else
{
if(hash[i] == 0)
sum = (sum + get(i)) % mod;
else
sum = (sum + hash[i]) % mod;
} if(n / i != i)
{
if(n / i >= 1000000)
sum = (sum + get(n/ i)) % mod;
else
{
if(hash[n / i] == 0)
sum = (sum + get(n / i)) % mod;
else
sum = (sum + hash[n / i]) % mod;
}
}
}
}
if(n < 1000000)
hash[n] = (pow(2,n) - sum - 2 + mod) % mod;
return (pow(2,n) - sum - 2 + mod) % mod;
}
int main()
{
memset(hash,0,sizeof(hash));
while(~scanf("%d",&n))
{
printf("%d ",get(n));
}
return 0;
}