problem DescriptionA string consisting of 0 and 1 cannot be represented as a string connected by several identical smaller strings, called primitive strings, and how many primitive strings are of n (n<=100000000) long.
The answer mod2008.
For example, 100100 is not an primitive string, because he is composed of two 100, and 1101 is the primitive string.
InputThe input includes multiple data, one row per data, and an integer n, which represents the length of the string.
OutputFor each test data, the output line, representing how many meet the requirements of the primitive string, the answer mod2008.
Sample Input
1
2
3
4
Sample Output
2
2
6
12
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
map<int, int >mp;
const int mod=2008;
int powmod (int a,int n)
{
if (n==0) return 1;
int X=powmod (A,N/2)%mod;
Long Long ans= (long Long) x*x%mod;
if (n%2==1) ans=ans*a%mod;
return (int) ans;
The key is to find the approximate n ...
int sol (int n)
{
if (mp[n]!=0) return mp[n];
Mp[n]=powmod (2,n)-2;
for (int i=2;i*i<=n;i++) {// why not I<=N/2, in order to prevent timeouts, approximate (similar to the method of prime number)
//y=n*m, effective reduction, is optimized.
if (n%i==0) {
mp[n]= (Mp[n]-sol (i) +mod)%mod;
if (n/i!=i) mp[n]= (Mp[n]-sol (n/i) +mod)%mod;
}
}
return mp[n];
}
int main ()
{
int n;
while (scanf ("%d", &n)!=eof) {
mp[0]=0;
mp[1]=2;
mp[2]=2;
if (n==0) {
printf ("0\n");
Continue;
}
printf ("%d\n", Sol (n));
}
return 0;
}