POJ3696 The Luckiest number
题意
Language:Default
The Luckiest number
Description Chinese people think of '8' as the lucky digit. Bob also likes digit '8'. Moreover, Bob has his own lucky number L. Now he wants to construct his luckiest number which is the minimum among all positive integers that are a multiple of L and consist of only digit '8'. Input The input consists of multiple test cases. Each test case contains exactly one line containing L(1 ≤ L ≤ 2,000,000,000). The last test case is followed by a line containing a zero. Output For each test case, print a line containing the test case number( beginning with 1) followed by a integer which is the length of Bob's luckiest number. If Bob can't construct his luckiest number, print a zero. Sample Input 8 Sample Output Case 1: 1 Source |
分析
\therefore 9L | 8(10^x-1) \\
\therefore \frac{9L}{\gcd(L,8)} | 10^x-1 \\
\therefore 10^x \equiv 1 (\bmod \frac{9L}{\gcd(L,8)}) \\
\because a^x \equiv 1 (\bmod n) \rightarrow \gcd(a,n)=1,x|\varphi(n) \\
\therefore x|\varphi(\frac{9L}{\gcd(L,8)})
\]
所以枚举即可。时间复杂度\(O(\sqrt{L} \log L)\)
代码
#include<iostream>
#include<cmath>
#define rg register
#define il inline
#define co const
template<class T>il T read(){
rg T data=0,w=1;
rg char ch=getchar();
while(!isdigit(ch)){
if(ch=='-') w=-1;
ch=getchar();
}
while(isdigit(ch))
data=data*10+ch-'0',ch=getchar();
return data*w;
}
template<class T>il T read(rg T&x){
return x=read<T>();
}
typedef long long ll;
ll L,d,k,p,s,i,num=0;
ll gcd(ll x,ll y){
return y?gcd(y,x%y):x;
}
ll ksc(ll a,ll b,ll c){
ll ans=0;
while(b){
if(b&1) ans=(ans+a)%c;
a=a*2%c;
b>>=1;
}
return ans;
}
ll ksm(ll a,ll b,ll c){
ll ans=1%c;
a%=c;
while(b){
if(b&1) ans=ksc(ans,a,c);
a=ksc(a,a,c);
b>>=1;
}
return ans;
}
ll phi(ll n){
ll ans=n;
for(i=2;i*i<=n;++i)
if(n%i==0){
ans=ans/i*(i-1);
while(n%i==0) n/=i;
}
if(n>1) ans=ans/n*(n-1);
return ans;
}
ll number(){
d=gcd(L,8);
k=9*L/d;
if(gcd(k,10)!=1) return 0;
p=phi(k);
s=sqrt((double)p);
for(i=1;i<=s;++i)
if(p%i==0&&ksm(10,i,k)==1)
return i;
for(i=s-1;i;--i)
if(p%i==0&&ksm(10,p/i,k)==1)
return p/i;
return 0;
}
int main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
while(read(L)) printf("Case %lld: %lld\n",++num,number());
return 0;
}
POJ3696 The Luckiest number的更多相关文章
- POJ3696:The Luckiest number(欧拉函数||求某数最小的满足题意的因子)
Chinese people think of '8' as the lucky digit. Bob also likes digit '8'. Moreover, Bob has his own ...
- [POJ3696]The Luckiest number(数论)
题目:http://poj.org/problem?id=3696 题意:给你一个数字L,你要求出一个数N,使得N是L的倍数,且N的每位数都必须是8,输出N的位数(如果不存在输出0) 分析: 首先我们 ...
- POJ3696 The Luckiest Number 欧拉定理
昨天终于把欧拉定理的证明看明白了...于是兴冲冲地写了2道题,发现自己啥都不会qwq 题意:给定一个正整数L<=2E+9,求至少多少个8连在一起组成正整数是L的倍数. 这很有意思么... 首先, ...
- poj 3696 The Luckiest Number
The Luckiest Number 题目大意:给你一个int范围内的正整数n,求这样的最小的x,使得:连续的x个8可以被n整除. 注释:如果无解输出0.poj多组数据,第i组数据前面加上Case ...
- POJ_3696 The Luckiest number 【欧拉定理+同余式+对取模的理解】
一.题目 Chinese people think of '8' as the lucky digit. Bob also likes digit '8'. Moreover, Bob has his ...
- poj_3696_The Luckiest number
Chinese people think of '8' as the lucky digit. Bob also likes digit '8'. Moreover, Bob has his own ...
- HDU 2462 The Luckiest number
The Luckiest number Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Ori ...
- The Luckiest number(hdu2462)
The Luckiest number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- 「POJ3696」The Luckiest number【数论,欧拉函数】
# 题解 一道数论欧拉函数和欧拉定理的入门好题. 虽然我提交的时候POJ炸掉了,但是在hdu里面A掉了,应该是一样的吧. 首先我们需要求的这个数一定可以表示成\(\frac{(10^x-1)}{9}\ ...
随机推荐
- 向Oracle 数据表中插入一条带有日期类型的数据
有一张表:batch(批次表) 表的字段如下: 第一种情况: 现在需要插入一条当前的系统时间 sql 如下: insert into batch (batch_id, cus_id, batch_nu ...
- bzoj1627 / P2873 [USACO07DEC]泥水坑Mud Puddles
P2873 [USACO07DEC]泥水坑Mud Puddles bfs入门. 对于坐标为负的情况,我们可以给数组下标加上$abs(min(minx,miny))$转正(根据题意判断) #includ ...
- Python3.x获取网页源码
Python3.x获取网页源码 1,获取网页的头部信息以确定网页的编码方式: import urllib.request res = urllib.request.urlopen('http://ww ...
- 20145105 《Java程序设计》实验一总结
实验一 Java开发环境的熟悉 一. 实验内容: (一)使用JDK编译.运行简单的程序 (二)使用idea编辑.编译.运行.调试Java程序. 二. 实验步骤: (一) 命令行下J ...
- linux及安全第七周总结——20135227黄晓妍
实验部分 首先clone最新的menu 我们可以看到,test.c里多了一个exec的功能,它的代码和fork基本一致,多了一项加载hello rootfs也有一些变化 执行一下exec 让我们启动一 ...
- 20145326 《Java程序设计》第6周学习总结
20145326 <Java程序设计>第6周学习总结 教材学习内容总结 第十章 一.使用InputStream与OutputStream 1.串流设计的概念 想活用输入/输出API,一定要 ...
- 封装JS实现Ajax
这两天仔细理解了一下Ajax,然后整理封装了一下,如果有什么不对的地方,请指教,谢谢! AJAX AJAX = Asynchronous JavaScript and XML(异步的 JavaScri ...
- Spring Cloud OAuth2(一) 搭建授权服务
概要 本文内容主要为spring cloud 授权服务的搭建,采用jwt认证. GitHub 地址:https://github.com/fp2952/spring-cloud-base/tree/m ...
- 框架-spring源码分析(一)
框架-spring源码分析(一) 参考: https://www.cnblogs.com/heavenyes/p/3933642.html http://www.cnblogs.com/BINGJJF ...
- jQuery实现鼠标点击Div区域外隐藏Div
冒泡定义:当一个元素上的事件被触发的时候,比如说鼠标点击了一个按钮,同样的事件将会在那个元素的所有祖先元素中被触发.这一过程被称为事件冒泡:这个事件从原始元素开始一直冒泡到DOM树的最上层.(摘自网络 ...