快速幂1007
来源:互联网 发布:陈巧生香炉官网淘宝网 编辑:程序博客网 时间:2024/06/03 17:19
本原串
Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 31 Accepted Submission(s) : 15
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
由0和1组成的串中,不能表示为由几个相同的较小的串连接成的串,称为本原串,有多少个长为n(n<=100000000)的本原串?
答案mod2008.
例如,100100不是本原串,因为他是由两个100组成,而1101是本原串。
答案mod2008.
例如,100100不是本原串,因为他是由两个100组成,而1101是本原串。
Input
输入包括多个数据,每个数据一行,包括一个整数n,代表串的长度。
Output
对于每个测试数据,输出一行,代表有多少个符合要求本原串,答案mod2008.
Sample Input
1234
Sample Output
22612
思路:可以用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;}
阅读全文
0 0
- 快速幂1007
- 快速矩阵快速幂
- 快速幂,快速幂取模
- 快速幂 + 快速幂取模
- 快速幂 快速幂取模
- 快速幂&&快速乘法
- 快速幂&快速乘
- 快速幂 快速乘法
- 快速幂 快速幂取模
- 快速幂+快速乘法
- 【快速幂】【快速幂取模】
- 快速乘法-快速幂
- 快速乘/快速幂/矩阵快速幂
- 快速乘 快速幂 矩阵快速幂
- 快速幂,快速幂取模,矩阵快速幂
- 快速幂
- 快速幂
- 快速幂
- python中常见的几种错误
- pytthon-异常处理与调试
- Linux命令学习之五
- Android Wi-Fi 查看信道命令
- kaggle Code :树叶分类 sklearn分类器应用
- 快速幂1007
- Hadoop I/O操作
- 二叉树的深度遍历 递归 和 堆栈法
- Java是什么?
- 集合中的集合_存储和遍历(增强型for循环和迭代器)
- apache-comnons系列之commons-io-2.5 org.apache.commons.io.IOUtils学习笔记
- HDU
- NKOJ 4038(CQOI 2017) 小Q的棋盘(贪心)
- 简单的学生排序系统