51nod-1359: 循环探求
【传送门:51nod-1359】
简要题意:
给出n和k,求出最小的x满足$n^{x}≡n(mod\;10^{k})$
题解:
真是一道有(du)趣(liu)题目
首先我们设X[k-1]为$n^{x}≡n(mod\;10^{k-1})$成立的最小的x
那么我们就可以得到$n^{X[k-1]}≡n(mod\;10^{k-1})$
设$N[k-1]=n^{X[k-1]}$
设t为任意值,可以发现$n^{t*X[k-1]}≡N[k-1]^{t}(mod\;10^{k-1})$
假设t*X[k-1]为满足$n^{x}≡n(mod\;10^{k})$的最小的x的话,其实可以知道变的只有第k位,而第1到第k-1位仍然是不变的,那么我们对于一个k就枚举t,因为抽屉原理,所以N[k-1]^t的第k位最多只有10种情况,t枚举到12都仍未找到则说明不存在x,就直接输出1
否则将得到的t连乘,最后+1就是答案了
PS:为了不超时,高精度的时候要控制长度在k以内,不会影响结果
参考代码:
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
struct node
{
int a[],len;
node()
{
len=;
memset(a,,sizeof(a));
}
}N,d;
char st[];int k;
node multi(node n1,node n2)
{
node no;no.len=k;
for(int i=;i<=k;i++)
{
for(int j=;j+i-<=k;j++) no.a[i+j-]+=n1.a[i]*n2.a[j];
}
for(int i=;i<=no.len;i++)
{
no.a[i+]+=no.a[i]/;
no.a[i]%=;
}
return no;
}
node solve(node n1,int n2)
{
node no;no.len=n1.len;
for(int i=;i<=no.len;i++) no.a[i]=n1.a[i]*n2;
for(int i=;i<=no.len;i++)
{
no.a[i+]+=no.a[i]/;
no.a[i]%=;
}
int i=no.len;
while(no.a[i+]>)
{
i++;
no.a[i+]+=no.a[i]/;
no.a[i]%=;
}
no.len=i;
return no;
}
int main()
{
scanf("%s%d",st+,&k);
int len=strlen(st+);N.len=len;
for(int i=;i<=len;i++) N.a[i]=st[len-i+]-'';
d.a[]=;d.len=;
node B=N,p,x;
for(int i=;i<=k;i++)
{
int t=;
x=B;
while(t<=)
{
p=multi(N,B);
if(p.a[i]==N.a[i]) break;
B=multi(B,x);t++;
}
if(t>){printf("1\n");return ;}
d=solve(d,t);
}
d.a[]++;
for(int i=;i<=d.len;i++)
{
d.a[i+]+=d.a[i]/;
d.a[i]%=;
}
int i=d.len;
while(d.a[i+]>)
{
i++;
d.a[i+]+=d.a[i]/;
d.a[i]%=;
}
d.len=i;
for(int i=d.len;i>=;i--) printf("%d",d.a[i]);
printf("\n");
return ;
}
51nod-1359: 循环探求的更多相关文章
- 51nod 1050 循环数组最大子段和
题目链接:51nod 1050 循环数组最大子段和 #include<stdio.h> #include<algorithm> using namespace std; ; l ...
- 51nod 1050 循环数组最大子段和 (dp)
http://www.51nod.com/onlineJudge/questionCode.html#problemId=1050¬iceId=13385 参考:http://blog. ...
- 51nod 1050 循环数组最大子段和 单调队列优化DP
题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1050 这个呢,这个题之前 求一遍最大值 然后求一遍最小值 ...
- 51Nod 1050 循环数组最大子段和 | DP
Input示例 6 -2 11 -4 13 -5 -2 Output示例 20 分析: 有两种可能,第一种为正常从[1 - n]序列中的最大子字段和:第二种为数组的total_sum - ([1-n] ...
- 51nod 1050 循环数组最大子段和【环形DP/最大子段和/正难则反】
1050 循环数组最大子段和 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 收藏 关注 N个整数组成的循环序列a[1],a[2],a[3],…,a[n],求该 ...
- 51nod 1050 循环数组最大子段和【动态规划】
N个整数组成的循环序列a[1],a[2],a[3],-,a[n],求该序列如a[i]+a[i+1]+-+a[j]的连续的子段和的最大值(循环序列是指n个数围成一个圈,因此需要考虑a[n-1],a[n] ...
- 基础dp 记录
51nod 1134 最长递增子序列 #include<iostream> #include<cstdio> #include<cstring> #include& ...
- 51nod 循环数组最大子段和
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1050 对于普通的数组,只要求一次最大子段和即可.但是这题是可以循环的,所 ...
- 51nod 1035 最长的循环节 数学
1035 最长的循环节 题目连接: https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1035 Description 正整 ...
随机推荐
- hdu5592/BestCoder Round #65 树状数组寻找第K大
ZYB's Premutation Memory Limit: 131072/131072 K (Java/Others) 问题描述 ZYBZYB有一个排列PP,但他只记得PP中每个前缀区间的逆 ...
- UVA - 12230 Crossing Rivers 概率期望
You live in a village but work in another village. You decided to follow the straight path between y ...
- linux含有某字符串的文件
find .|xargs grep -ri "IBM" -l 只列出文件名:grep -rn "Item" * -l pattern files
- 用shell脚本实现linux系统上wifi模式(STA和soft AP)的转换
转载请注明出处:http://blog.csdn.net/hellomxj1/ 功能:在linux系统上实现wifi STA与AP功能的转换 实现成果:1.加入wifipassword账户add_wi ...
- WebBrowser网页操作之提取获取元素和标签(完整篇)
最近使用WebBrower做了几个Hook小程序,收集积累如下: using System; using System.Collections.Generic; using System.Linq; ...
- JavaScript中闭包的理解
1.什么是闭包 我个人理解闭包就是函数中嵌套函数,但是嵌套的那个函数必须是返回值,才构成闭包: <!DOCTYPE html> <html> <head> < ...
- 服务端 | Linux 学习总结 (一)
http://billie66.github.io/TLCL/book/ 1.Ubuntu && linux shell 命令 Ubuntu两个重要版本:12.04和14.04 在终端 ...
- SSH三个主流框架环境的搭建
part 1 Hibernate环境的搭建 part2 struts2环境的搭建 第一步:从struts2官网下载需要的各种资料和jar包 第二步:在ecplise里面创建web项目,然后在web ...
- PHP的分页
页面的效果 页面的css @CHARSET "UTF-8"; *{ margin:0; padding:0; } body{ width:800px; margin:0 auto; ...
- zabbix-server端监控MySQL服务
Zabbix 监控MySQL数据库 为server.zabbix,com 添加服务模块 创建MySQL服务图形 Server.zabbix.com 服务器操作 [root@server ~]# cd ...