很有意思的一个签到题 然而考场上并没有切掉

$1111...111=K(mod\;m)$

$10^{x}=9K+1(mod\;m)$

用$BSGS$求解即可

模数爆了$int$,需要快速乘,然而模数是$10^{11}$级别并不是特别大,可以利用位运算进行$O(1)$快速乘

 #include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N1 4000010
#define M1 400010
#define ll long long
#define dd double
#define cll const long long
#define inf 23333333333333333ll
using namespace std; ll K,M,A;
struct Hsh{
#define maxn 4000000
int head[N1],nxt[M1],val[M1],cte;ll to[M1];
void ins(ll x,int w)
{
int u=x%maxn; ll v;
for(int j=head[u];j;j=nxt[j])
{
v=to[j];
if(v==x) return;
}
cte++; to[cte]=x; nxt[cte]=head[u];
val[cte]=w; head[u]=cte;
}
int find(ll x)
{
int u=x%maxn; ll v;
for(int j=head[u];j;j=nxt[j])
{
v=to[j];
if(v==x) return val[j];
}
return -;
}
}h; inline ll qmul(ll a,ll b){
return ((((a>>)*b%M)<<)%M+(a&((<<)-))*b%M)%M;
}
ll qpow(ll x,ll y)
{
ll ans=;
while(y){
if(y&) ans=qmul(ans,x);
x=qmul(x,x); y>>=;
}return ans;
} int main()
{
scanf("%lld%lld",&K,&M);
A=(9ll*K+)%M;
ll sq=sqrt(M),i,pw,now,ans;
for(pw=qpow(10ll,sq),now=,i=;(i-)*sq<M;i++)
{
now=qmul(now,pw);
h.ins(now,i);
}
for(now=A,ans=inf,i=;i<sq;i++)
{
pw=h.find(now);
if(pw!=-) ans=min(ans,pw*sq-i);
now=qmul(now,10ll);
}
printf("%lld\n",ans);
return ;
}

最新文章

  1. 深入理解javascript选择器API系列第一篇——4种元素选择器
  2. yii框架的增删改查
  3. Reverse Linked List II 单向链表逆序(部分逆序)
  4. 关于Oracle的性能调整(一)
  5. Python处理时间 time &amp;&amp; datetime 模块
  6. typedef (还需经常看看加深理解)
  7. Android 注入详解
  8. Android 解析JSONObject以及JSONArray对比
  9. centos6.5安装gcc6.1等c++环境
  10. 一个简单的TestNG例子
  11. jenkins服务器安装
  12. MP3文件结构及解码概述
  13. Unable to run mksdcard SDK tool.
  14. 监控concurrent 正在执行的sql
  15. 谷歌浏览器javascript调试教程
  16. ucos调度器详解
  17. Android常用adb命令
  18. python+selenium自动化测试_1
  19. 《ServerSuperIO Designer IDE使用教程》-4.增加台达PLC驱动及使用教程,从0到1的改变。发布:v4.2.3版本
  20. CSAPP:第二章学习笔记:斗之气2段

热门文章

  1. Sublime Text 3常用插件—Emmet
  2. 3.2 re--正則表達式操作(Regular expression operations)
  3. 为Android开发人员定制的搜索引擎
  4. python爬虫解决百度贴吧登陆验证码问题
  5. CSU 1506 Problem D: Double Shortest Paths(最小费用最大流)
  6. 《转》Ceilometer Alarm API 參数具体解释 及 举例说明
  7. Python 中的循环与 else
  8. 【POJ 2976】 Dropping Tests
  9. org.springframework.beans.factory.config.PropertyPlaceholderConfigurer的systemPropertiesModeName属性
  10. hihoCoder-1633 ACM-ICPC北京赛区2017 G.Liaoning Ship’s Voyage 线段与三角形规范相交