给定一个数,判断是否存在一个全由8组成的数为这个数的倍数

若存在则输出这个数的长度,否则输出0

/*
个人感觉很神的一道题目。
如果有解的话,会有一个p满足:(10^x-1)/9*8=L*p
=> 10^x-1=9*L*p/8
设m=9*L/gcd(L,8)
则存在p1使得 10^x-1=m*p1
=> 10^x=1(mod m)
根据欧拉定理 10^φ(m)=1(mod m)
所以x一定是φ(m)的因数(这好像是某个定理)。
*/
#include<iostream>
#include<cstdio>
#define lon long long
#define N 400010
#ifdef unix
#define LL "%lld"
#else
#define LL "%I64d"
#endif
using namespace std;
int prime[N],f[N],num,qlen;
lon q[N];
void get_prime(){
for(int i=;i<N;i++){
if(!f[i]) prime[++num]=i;
for(int j=;j<=num;j++){
if(i*prime[j]>=N) break;
f[i*prime[j]]=;
if(i%prime[j]==) break;
}
}
}
lon gcd(lon a,lon b){
if(!b) return a;
return gcd(b,a%b);
}
lon euler(lon x){
lon res=x;
for(lon i=;i*i<=x;i++)
if(x%i==){
res-=res/i;
while(x%i==) x/=i;
}
if(x>) res-=res/x;
return res;
}
void get_q(lon n){
qlen=;
for(int i=;i<=num&&n>;i++){
while(n%(lon)prime[i]==){
n/=prime[i];
q[++qlen]=prime[i];
}
}
if(n>) q[++qlen]=n;
}
lon mul(lon a,lon b,lon mod){
lon base=a,r=;
while(b){
if(b&) r+=base;r%=mod;
base+=base;base%=mod;
b>>=;
}
return r;
}
lon poww(lon a,lon b,lon mod){
lon base=a,r=;
while(b){
if(b&) r=mul(r,base,mod);
base=mul(base,base,mod);
b>>=;
}
return r;
}
int main(){
int cas=;lon L;get_prime();
while(scanf(LL,&L)&&L){
lon m=*L/gcd(L,);
if(gcd(m,)>){
printf("Case %d: 0\n",++cas);
continue;
}
lon x=euler(m);get_q(x);
for(int i=;i<=qlen;i++){
if(poww(,x/q[i],m)==){
x/=q[i];
}
}
printf("Case %d: ",++cas);
printf(LL,x);printf("\n");
}
return ;
}
 

The Luckiest number(hdu 2462)的更多相关文章

  1. hihoCoder 1432 : JiLi Number(吉利数)

    hihoCoder #1432 : JiLi Number(吉利数) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - 题目描述 Driver Ji l ...

  2. 2道acm编程题(2014):1.编写一个浏览器输入输出(hdu acm1088);2.encoding(hdu1020)

    //1088(参考博客:http://blog.csdn.net/libin56842/article/details/8950688)//1.编写一个浏览器输入输出(hdu acm1088)://思 ...

  3. 1117 Eddington Number (25 分)

    1117 Eddington Number (25 分) British astronomer Eddington liked to ride a bike. It is said that in o ...

  4. 1038 Recover the Smallest Number (30 分)

    1038 Recover the Smallest Number (30 分) Given a collection of number segments, you are supposed to r ...

  5. 1019 General Palindromic Number (20 分)

    1019 General Palindromic Number (20 分) A number that will be the same when it is written forwards or ...

  6. [PAT] 1144 The Missing Number(20 分)

    1144 The Missing Number(20 分) Given N integers, you are supposed to find the smallest positive integ ...

  7. 数据类型总结——Number(数值类型)

    相关文章 简书原文:https://www.jianshu.com/p/9fb573ef10da 数据类型总结——概述:https://www.cnblogs.com/shcrk/p/9266015. ...

  8. 数据库number(4,3)表示什么

    1 你看 number(4,3)是表示 这个数 一共有4位是有效位,后面的3 表示有3个是小数也就是这个数 只能是1.234,这样格式的 最大只能是9.999,2 number(3,4) 表示这个数 ...

  9. The Luckiest number(hdu2462)

    The Luckiest number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

随机推荐

  1. Java第11次作业:什么是继承?继承的好处?什么是覆写?super()?构造代码块?子父类初始化顺序? 抽象类能用final声明吗?final关键字声明类 方法 变量以及全局常量?抽象类的构造方法?

    什么是继承? 继承是以父类为基础,子类可以增加新的数据或新的功能.子类不能选择性地继承父类.这种技术使得复用以前的代码非常容易. JAVA不支持多继承,单继承使JAVA的继承关系很简单,一个类只能有一 ...

  2. 几种排序算法的比较转自http://blog.csdn.net/keenweiwei/article/details/3697452

    1冒泡排序: 已知一组无需数据a[1],a[2],a[3],a[4],a[5][a[n],将其按升序排列,首先找出这组数据中最大值,将a[1]与a[2]比较,若a[1]大,则交换两者的值,否则不变,在 ...

  3. Find the Longest Word in a String-freecodecamp算法题目

    Find the Longest Word in a String(找出最长单词) 要求 在句子中找出最长的单词,并返回它的长度 函数的返回值应该是一个数字. 思路 用.split(' ')将句子分隔 ...

  4. Latex使用笔记,中文,字号等

    中文 编译器选择的xelatex 或者lualatex 我试过的两种方式(都是基于ctex的). 直接使用ctex的基本documentclass \documentclass[UTF8]{ctexa ...

  5. 洛谷 P1147 连续自然数和

    洛谷 P1147 连续自然数和 看到dalao们的各种高深方法,本蒟蒻一个都没看懂... 于是,我来发一篇蒟蒻友好型的简单题解 #include<bits/stdc++.h> using ...

  6. 【python】python环境搭建

    本文主要用于记录python环境的搭建一些不常用的命令,其他的安装步骤在其他大师可以找到就不详细列出了.(注:以下操作都是在Ubuntu14.04LTS版本) 一.环境查询相关 1.查询当前pytho ...

  7. 拓展jQuery的serialize(),将form表单转化为json对象

    jQuery 的 serialize() 方法经常会报 Uncaught TypeError: JSON.serializeObject is not a function 的错误, 原装的方法真的一 ...

  8. 多进程 multiprocessing 多线程Threading 线程池和进程池concurrent.futures

    multiprocessing.procsess 定义一个函数 def func():pass 在if __name__=="__main__":中实例化 p = process( ...

  9. ACM-ICPC 2018 徐州赛区网络预赛 F. Features Track

    262144K   Morgana is learning computer vision, and he likes cats, too. One day he wants to find the ...

  10. linux学习-主机的细部权限规划:ACL 的使用

    传统的权限仅有三种身份 (owner, group, others) 搭配三种权限 (r,w,x) 而已,并没有办法单纯的针对某一个使用者或某一个群 组来设定特定的权限需求,此时就得要使用 ACL 这 ...