给定一个数,判断是否存在一个全由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. Google「Game Builder」:不懂编程,也能开发 3D 游戏

    简评: 之前微软曾推出过「Kodu Game Lab」,它可以让完全没有编程经验的人通过简单的步骤打造属于自己的游戏.无独有偶,Google 最近在 Steam 也推出了类似的程序「Game Buil ...

  2. java基础—注解annotation

    一.认识注解 注解(Annotation)很重要,未来的开发模式都是基于注解的,JPA是基于注解的,Spring2.5以上都是基于注解的,Hibernate3.x以后也是基于注解的,现在的Struts ...

  3. springmvc的第一个程序

    文中用的框架版本:spring 3,hibernate 3,没有的,自己上网下. web.xml配置: <?xml version="1.0" encoding=" ...

  4. 01_5_Struts_ActionMethod_DMI_动态方法调用

    01_5_Struts_ActionMethod_DMI_动态方法调用 1. ActionMethod_DMI_动态方法调用 Action执行的时候并不一定要执行execute()方法 可以在配置文件 ...

  5. UIPopoverController

    if (popOver == nil) { popOver = [[UIPopoverController alloc] initWithContentViewController:viewVC]; ...

  6. 35. Search Insert Position@python

    Given a sorted array and a target value, return the index if the target is found. If not, return the ...

  7. STL容器之Array[转]

    转自https://blog.csdn.net/sin_geek/article/details/51067874 作者 Sin_Geek 简介 array在头文件<array> 中定义 ...

  8. 【思维题 并查集 图论】bzoj1576: [Usaco2009 Jan]安全路经Travel

    有趣的思考题 Description Input * 第一行: 两个空格分开的数, N和M * 第2..M+1行: 三个空格分开的数a_i, b_i,和t_i Output * 第1..N-1行: 第 ...

  9. 洛谷 2387/BZOJ 3669 魔法森林

    3669: [Noi2014]魔法森林 Time Limit: 30 Sec  Memory Limit: 512 MBSubmit: 3765  Solved: 2402[Submit][Statu ...

  10. 01、Linux介绍

    一. Linux介绍 Linux是一套免费使用和自由传播的类Unix操作系统,是一个基于POSIX和UNIX的多用户.多任务.支持多线程和多CPU的操作系统.它能运行主要的UNIX工具软件.应用程序和 ...