HDU 2462 The Luckiest number
The Luckiest number
This problem will be judged on HDU. Original ID: 2462
64-bit integer IO format: %I64d Java class name: Main
Input
The last test case is followed by a line containing a zero.
Output
Sample Input
8
11
16
0
Sample Output
Case 1: 1
Case 2: 2
Case 3: 0
Source
首先,由题意可以得出,(10^x - 1)/ 9 * 8 = L * p(p是一个未知数,但必定是整数)。
然后对上式进行移项处理,得:(10^x - 1) = 9 * L * p / 8。
设m = 9 * L / gcd(L, 8),则有(10^x - 1) = m * p'。p’是必然存在的一个整数。
然后问题就转化成为了 10^x = 1(mod m),观察此式,显然,m和10必定互质。
于是根据欧拉定理,10^(Euler(m)) = 1(mod m) 。由于题目要求最小的解,解必然是Euler(m)的因子。
转自 OK_again
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int maxn = ;
LL mul(LL a, LL b, LL mod) {
LL ret = ;
while(b) {
if(b&) ret = (ret + a) % mod;
a = (a<<)%mod;
b >>= ;
}
return ret;
}
LL quickPow(LL base,LL index,LL mod){
LL ret = ;
while(index){
if(index&) ret = mul(ret,base,mod);
index >>= ;
base = mul(base,base,mod);
}
return ret;
}
bool np[maxn] = {true,true};
int p[maxn],tot;
void init(){
for(int i = ; i < maxn; ++i){
if(!np[i]) p[tot++] = i;
for(int j = ; j < tot && p[j]*i < maxn; ++j){
np[p[j]*i] = true;
if(i%p[j] == ) break;
}
}
}
LL Euler(LL n){
LL ret = n;
for(int i = ; (LL)p[i]*p[i] <= n; ++i){
if(n%p[i] == ){
ret = ret/p[i]*(p[i] - );
while(n%p[i] == ) n /= p[i];
}
}
if(n > ) ret = ret/n*(n-);
return ret;
}
vector<int>F;
void Fn(LL n){
F.clear();
for(int i = ; i < tot && n > ; ++i){
while(n%p[i] == ){
n /= p[i];
F.push_back(p[i]);
}
}
if(n > ) F.push_back(n);
}
int main(){
init();
LL L;
int cs = ;
while(scanf("%I64d",&L),L){
LL m = *L/__gcd(L,8LL);
if(__gcd(m,10LL) != ){
printf("Case %d: 0\n",cs++);
continue;
}
LL x = Euler(m);
Fn(x);
for(auto it:F)
if(quickPow(,x/it,m) == ) x /= it;
printf("Case %d: %I64d\n",cs++,x);
}
return ;
}
HDU 2462 The Luckiest number的更多相关文章
- poj 3696 The Luckiest Number
The Luckiest Number 题目大意:给你一个int范围内的正整数n,求这样的最小的x,使得:连续的x个8可以被n整除. 注释:如果无解输出0.poj多组数据,第i组数据前面加上Case ...
- POJ3696 The Luckiest number
题意 Language:Default The Luckiest number Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7 ...
- HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对)
HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对) 题意分析 给出n个数的序列,a1,a2,a3--an,ai∈[0,n-1],求环序列中逆序对 ...
- hdu 6216 A Cubic number and A Cubic Number【数学题】
hdu 6216 A Cubic number and A Cubic Number[数学] 题意:判断一个素数是否是两个立方数之差,就是验差分.. 题解:只有相邻两立方数之差才可能,,因为x^3-y ...
- 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 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- POJ3696:The Luckiest number(欧拉函数||求某数最小的满足题意的因子)
Chinese people think of '8' as the lucky digit. Bob also likes digit '8'. Moreover, Bob has his own ...
- HDU 1394 Minimum Inversion Number(线段树求最小逆序数对)
HDU 1394 Minimum Inversion Number(线段树求最小逆序数对) ACM 题目地址:HDU 1394 Minimum Inversion Number 题意: 给一个序列由 ...
随机推荐
- SpringCloud开发学习总结(七)—— 声明式服务调用Feign(二)
参数绑定 在上一章的示例中,我们使用Spring Cloud Feign实现的是一个不带参数的REST服务绑定.然而现实系统中的各种业务接口要比它复杂得多,我们有时会在HTTP的各个位置传入各种不同类 ...
- 513 Find Bottom Left Tree Value 找树左下角的值
给定一个二叉树,在树的最后一行找到最左边的值. 详见:https://leetcode.com/problems/find-bottom-left-tree-value/description/ C+ ...
- hash 【模板】
hash 功能: hash一般用于快速判断两个或多个字符串是否匹配. 实现 : 想一想,如果比较两个数子的话是很方便的很快,那么我们把整个字符串看成一个大数. 它是base进制的len位数.但 ...
- idea安装mybatis插件
简介 mybatis_plus主要的作用是自动导航,如下图 点击箭头会跳转到对应的dao接口中,同样,dao接口中也有这样的箭头,点击之后会跳转到对应的sql映射语句处. 还有一个功能就是检查mapp ...
- C/S WinForm自动升级
这二天刚好完成一个C/S 自动升级的功能 代码分享一下 /// <summary> /// 版本检测 /// </summary> public class ...
- Java GC机制简要总结(Java垃圾回收的基本工作原理)
第一次编辑 2019-05-07 01:09:39 垃圾回收的对象 程序中的不可用对象(不存活的对象,没有任何引用),或者无用的变量信息等,在程序中长期存在会逐渐占用较多的内存空间,导致没有足够的空间 ...
- poj2184 Cow Exhibition
思路: dp+滚动数组. 类似01背包. 实现: #include <iostream> #include <cstdio> #include <algorithm> ...
- css3 blur模糊解决ie6-ie9兼容
css3 blur模糊是css3的新特性,但是不兼容ie6-ie9,以下代码可以解决此问题: filter: progid:DXImageTransform.Microsoft.Blur(Pixel ...
- wkWebView 的一些问题
导语 WKWebView 是苹果在 WWDC 2014 上推出的新一代 webView 组件,用以替代 UIKit 中笨重难用.内存泄漏的 UIWebView.WKWebView 拥有60fps滚动刷 ...
- Linux OpenGL 实践篇-11-shadow
OpenGL 阴影 在三维场景中,为了使场景看起来更加的真实,通常需要为其添加阴影,OpenGL可以使用很多种技术实现阴影,其中有一种非常经典的实现是使用一种叫阴影贴图的实现,在本节中我们将使用阴影贴 ...