hdu 2462 The Luckiest number
来源:互联网 发布:手机root软件 编辑:程序博客网 时间:2024/06/06 12:37
The Luckiest number
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
11
16
0
Sample Output
Case 1: 1
Case 2: 2
Case 3: 0
分析
这题一开始不会,但看了网上一些题解然后理了理思路,最后复现出来
题目的要求就是
就是
利用Euler定理,但是如果
由于
代码
#include<iostream>#include<cstdio>#include<cmath>using namespace std;typedef long long LL;LL gcd(LL a,LL b){ return b == 0? a : gcd(b, a%b);}LL mul(LL a, LL b, LL mod)// a * b % c{ LL res=0; while(b) { if(b&1) { res = (res+a) % mod; } a = (a<<1) % mod; b >>= 1; } return res;}LL quick(LL a, LL b, LL mod){ LL s=1,tmp=a; while(b) { if(b & 1) { s = mul(s,tmp,mod); } tmp = mul(tmp,tmp,mod); b >>= 1; } return s;}LL Euler(LL n){ LL m = (int)sqrt(n+0.5); LL res = n; for(LL i = 2; i <= m; ++i) { if(n%i == 0) { res = res / i * (i-1); while(n%i == 0) { n /= i; } } } if(n > 1) { res = res / n * (n-1); } return res;}int main(){ int cas = 0, d; LL L,m; while(cin>>L && L) { m = 9*L / gcd(L,8); cout<<"Case "<<++cas<<": "; d = gcd(10,m); if(d == 1) { LL phi = Euler(m); LL ans = phi; LL p = sqrt((double)phi); bool kk = 0; for(int i = 1; i <= p; i++) { if(phi%i == 0 && quick(10, i, m) == 1) { ans=i; kk=1; break; } } if(!kk) { for(int i=p; i >= 2; i--) { if(phi%i == 0 && quick(10, phi/i, m) == 1) { ans = phi/i; kk = 1; break; } } } cout<<ans<<endl; } else { cout<<"0"<<endl; } }}
- hdu 2462 The Luckiest number
- HDU 2462 The Luckiest number
- HDU 2462 The Luckiest number
- hdu 2462 The Luckiest number
- hdu 2462 The Luckiest number
- 【原创】【数论】HDU 2462 The Luckiest number
- hdu 2462 数学欧拉 The Luckiest number
- hdu 2462 The Luckiest number(快速乘取摸)
- POJ 3696/ HDU 2462 The Luckiest number (数论)
- poj The Luckiest number
- poj3696 The Luckiest number
- #POJ3696# The Luckiest number
- The Luckiest number POJ
- POJ 3696 The Luckiest number
- POJ 3696 The Luckiest number
- poj 3696 The Luckiest number
- poj 3696 The Luckiest number
- poj-3696 The Luckiest number
- 连接池学习(1)
- ECMASript、DOM、BOM
- 记录一点有意思的东西
- EM算法MATLAB代码及详细注解
- opencv中的相机标定学习
- hdu 2462 The Luckiest number
- Java IDE 的选择
- beego开发文档
- PHP项目入口文件为什么放在子目录
- 第七届山东省ACM省赛 E The Binding of Isaac
- Java中基于HttpServlet的反射机制(封装从view层页面接收到的数据于实体对象中)
- android listview分页加载的条目点击报错的问题
- CodeBlocks的常用快捷键
- AI基本概念