51Nod 最长的循环节(打表预处理)
正整数k的倒数1/k,写为10进制的小数如果为无限循环小数,则存在一个循环节,求<=n的数中,倒数循环节长度最长的那个数,假如存在多个最优的答案,输出所有答案中最大的那个数。
输入n(10 <= n <= 1000)
输出<=n的数中倒数循环节长度最长的那个数
10
7
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
#define mem(a) ((a,0,sizeof(a)))
typedef long long ll;
int a[][],b[],n;
int solve(int n)
{
int now=;
for(int i=;i<=;i++)
{
b[i]=now%n;
now=now%n;
now*=;
}
for(int i=;i>=;i--)
if(b[i]==b[]) return -i;
}
int main()
{
for(int i=;i<=;i++)
{
a[i][]=solve(i);
}
a[][]=;
for(int i=;i<=;i++)
{
if(a[i][]<a[i-][])
{
a[i][]=a[i-][];
a[i][]=a[i-][];
}
else a[i][]=i;
}
scanf("%d",&n);
printf("%d\n",a[n][]);
return ;
}
51Nod 最长的循环节(打表预处理)的更多相关文章
- 51nod 1035 最长的循环节 数学
1035 最长的循环节 题目连接: https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1035 Description 正整 ...
- 51 Nod 1035 最长的循环节 (此题还不是很懂,日后再看)
转自: https://blog.csdn.net/define_danmu_primer/article/details/52456763 51nod 1035 最长的循环节(无限小数的循环节) 2 ...
- UVA 11582 Colossal Fibonacci Numbers!(循环节打表+幂取模)
题目链接:https://cn.vjudge.net/problem/UVA-11582 /* 问题 输入a,b,n(0<a,b<2^64(a and bwill not both be ...
- AC日记——计算循环节长度 51nod 1035
最长的循环节 思路: 我们尝试一种最简单的方法,模拟: 如何模拟呢? 每个数,对它模k取余,如果它的余数没有出现过,就补0继续模: 所以,当一个余数出现两次时,当前的长度即为循环节长度: 来,上代码: ...
- Uva 12012 Detection of Extraterrestrial 求循环节个数为1-n的最长子串长度 KMP
题目链接:option=com_onlinejudge&Itemid=8&page=show_problem&problem=3163">点击打开链接 题意: ...
- HDU 3746 (KMP求最小循环节) Cyclic Nacklace
题意: 给出一个字符串,要求在后面添加最少的字符是的新串是循环的,且至少有两个循环节.输出最少需要添加字符的个数. 分析: 假设所给字符串为p[0...l-1],其长度为l 有这样一个结论: 这个串的 ...
- hdu 4333"Revolving Digits"(KMP求字符串最小循环节+拓展KMP)
传送门 题意: 此题意很好理解,便不在此赘述: 题解: 解题思路:KMP求字符串最小循环节+拓展KMP ①首先,根据KMP求字符串最小循环节的算法求出字符串s的最小循环节的长度,记为 k: ②根据拓展 ...
- 【文文殿下】浅谈KMP算法next数组与循环节的关系
KMP算法 KMP算法是一种字符串匹配算法,他可以在O(n+m)的时间内求出一个模式串在另一个模式串下出现的次数. KMP算法是利用next数组进行自匹配,然后来进行匹配的. Next数组 Next数 ...
- POJ2406Power Strings (最小循环节)(KMP||后缀数组)
Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc&quo ...
随机推荐
- zzulioj--1790-- 弹珠游戏(数学水题!)
弹珠游戏 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 14 Solved: 10 SubmitStatusWeb Board Descriptio ...
- Git 连接细节
Git 连接细节 首先创建Git 账号 https://github.com/ 下载Git https://git-scm.com/downloads 新建远程仓库 SSH keys : 打开 Git ...
- AOJ GRL_1_A: Single Source Shortest Path (Dijktra算法求单源最短路径,邻接表)
题目链接:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A Single Source Shortest Path In ...
- 虚拟机CentOS6.8下安装JDK
CentOS6.8下 首先下载JDK,执行命令如下: wget http://download.oracle.com/otn-pub/java/jdk/8u172-b11/a58eab1ec24242 ...
- JS 判断中英文字符长度
function strlen(str) { var len = 0; for (var i = 0; i < str.length; i++) { ...
- solarwind之安装
1. 安装组件 2. 安装组件sql 3. 安装 4. 接受协议 5. 安装路径 6. 安装状态 7. 继续 8. 激活 9. 完成安装
- Node_进阶_6
Node进阶第六天 一.复习 cookie是在res中设置,req中读取的.第一次的访问没有cookie. cookie的存储大小有限,kv对儿.对用户可见,用户可以禁用.清除cookie.可以被篡改 ...
- 移动端mete设置
<!DOCTYPE html> <!-- 使用 HTML5 doctype,不区分大小写 --> <html lang="zh-cmn-Hans"&g ...
- [洛谷P1835]素数密度
题目大意:求区间[l,r]中素数的个数($1\leq l,r\le 2^{31}$,$r-l\leq 10^6$). 解题思路:首先,用筛法筛出$2~\sqrt{r}$内的素数. 然后用这些素数筛l~ ...
- 使用systemctl自定义系统服务
1.创建系统服务文件,格式如下: [Unit] Description=httpd After=network.target [Service] Type=forking ExecStart=/usr ...