由0和1组成的串中,不能表示为由几个相同的较小的串连接成的串,称为本原串,有多少个长为n(n<=100000000)的本原串?

答案mod2008.

例如,100100不是本原串,因为他是由两个100组成,而1101是本原串。

Input

输入包括多个数据,每个数据一行,包括一个整数n,代表串的长度。

Output

对于每个测试数据,输出一行,代表有多少个符合要求本原串,答案mod2008.

Sample Input

1

2

3

4

Sample Output

2

2

6

12

解析:

考虑所有串减去非本原串。

长度为N的串最多组成 2N2^N2N种情况的串,当串全部为1或为0的时候不是本原串。

再举个例子,6的时候 6可以由三个长度为2的串组成,也可以由长度为3的两个穿组成,那么长度为2的组成方式其实是有四种00 01 10 11因为00 11组成的是全为1的或者,全为0的之前考虑过,所以不重复计算。在考虑长度为3的串,000 001 010 011 100 101 110 111 除了000 111之外还有六种,我们发现恰好为,其本原串的数量。

因此此题公式为:

2N−cal[i]其中i为因子,cal()为长度为i的本原串的数量2^N-cal[i] 其中i为因子,cal()为长度为i的本原串的数量2N−cal[i]其中i为因子,cal()为长度为i的本原串的数量

故可写出代码:

#include <cstring>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;
int m[10000000];
long long n,ans;
long long mod_pow(long long x,long long n,int mod)
{
long long res=1;
while(n)
{
if(n&1)
res=res*x%mod;
x=x*x%mod;
n>>=1;
}
return res;
}
int cal(long long n)
{
if(m[n]!=0)
return m[n];
m[n]=mod_pow(2,n,2008)-2;
for(int i=2;i*i<=n;i++)
{
if(n%i==0)
{
m[n]=(m[n]-cal(i)+2008)%2008;
if(i*i!=n)
m[n]=(m[n]-cal(n/i)+2008)%2008; }
}
return m[n];
}
int main()
{
m[0]=0;
m[1]=2;
m[2]=2;
while(scanf("%d",&n)!=EOF)
{
if(n<=2)
printf("%d\n",m[n]);
else
{
m[n]=cal(n);
printf("%d\n",m[n]);
}
}
}

数学--数论--HDU 2197 本原串 (推规律)的更多相关文章

  1. hdu 2197 本原串

    http://acm.hdu.edu.cn/showproblem.php?pid=2197 长度为n的01串有2的n次方个,再减去不符合要求的.不符合要求的字符串就是长度为n的约数的字符串. 递归处 ...

  2. 数学--数论--HDU - 6322 打表找规律

    In number theory, Euler's totient function φ(n) counts the positive integers up to a given integer n ...

  3. 数学--数论--HDU - 6124 Euler theorem (打表找规律)

    HazelFan is given two positive integers a,b, and he wants to calculate amodb. But now he forgets the ...

  4. 数学--数论--HDU 2582 F(N) 暴力打表找规律

    This time I need you to calculate the f(n) . (3<=n<=1000000) f(n)= Gcd(3)+Gcd(4)+-+Gcd(i)+-+Gc ...

  5. 数学--数论--HDU 1792 A New Change Problem (GCD+打表找规律)

    Problem Description Now given two kinds of coins A and B,which satisfy that GCD(A,B)=1.Here you can ...

  6. 数学--数论--HDU - 6395 Let us define a sequence as below 分段矩阵快速幂

    Your job is simple, for each task, you should output Fn module 109+7. Input The first line has only ...

  7. 数学--数论--Hdu 5793 A Boring Question (打表+逆元)

    There are an equation. ∑0≤k1,k2,⋯km≤n∏1⩽j<m(kj+1kj)%1000000007=? We define that (kj+1kj)=kj+1!kj! ...

  8. HDU 2197 本源串

    如果一个串能完全由其子串组成,那么这个串就不是本源串 求长度为n的本源串的个数. 由定义一个串如果不是本源串,那么他的长度一定是组成其子本源串的长度的(>=1) 整数倍. 那么长度为n的串总个数 ...

  9. 数学--数论--HDU 6063 RXD and math (跟莫比乌斯没有半毛钱关系的打表)

    RXD is a good mathematician. One day he wants to calculate: output the answer module 109+7. p1,p2,p3 ...

随机推荐

  1. (js描述的)数据结构[哈希表1.3](10)

    1.哈希表的完善 1.容量质数(limit):需要恒为质数,来确保元素的均匀分布. 1)普通算法: 判断一个数是否为质数 function isPrime(num) { for (var i = 2; ...

  2. 36 Thread 多线程

    /* * 多线程的实现方式: * 方式1:一种方法是将类声明为 Thread 的子类.该子类应重写 Thread 类的 run 方法.接下来可以分配并启动该子类的实例 * * Thread * Str ...

  3. Python Requests-学习笔记(5)-响应状态码

    我们可以检测响应状态码: r = requests.get('http://httpbin.org/get') r.status_code 为方便引用,Requests还附带了一个内置的状态码查询对象 ...

  4. 自己模拟的ftl 用法:

    基类 public class Ftl_object_data_model { //三种基本属性 private boolean canRead=true;//是否能读取 ;//长度 private ...

  5. CVE-2019-0193 远程命令执行-漏洞复现

    0x01 漏洞简介 Apache Solr 是一个开源的搜索服务器.Solr 使用 Java 语言开发,主要基于 HTTP 和 Apache Lucene 实现.此次漏洞出现在Apache Solr的 ...

  6. DVWA渗透笔记

    Command Injection Low <?php if( isset( $_POST[ 'Submit' ] ) ) { // Get input $target = $_REQUEST[ ...

  7. cxGrid增加一栏显示checkBox的设置方法

    鉴于本人首次设定cxGrid的CheckBox的时候费了很大劲,发现很多人都会碰到这个问题,现在总结一下,以供各位互相学习借鉴. 步骤如下(不分先后): 1. cxGrid添加完自己所需的所有字段后, ...

  8. L22 Data Augmentation数据增强

    数据 img2083 链接:https://pan.baidu.com/s/1LIrSH51bUgS-TcgGuCcniw 提取码:m4vq 数据cifar102021 链接:https://pan. ...

  9. ASE project demo:pdf

    欢迎使用 pdf ~ 主页面如下,整个app风格一致,保持简约舒适的视觉体验~ 侧边栏打开,可选择打开新的pdf文件,返回主页面,打开本地生词本,登录等操作~ 可以点击侧边栏OpenFile打开新的p ...

  10. C - Roads in the North DFS+树的直径

    Building and maintaining roads among communities in the far North is an expensive business. With thi ...