The Luckiest number(hdu 2462)
给定一个数,判断是否存在一个全由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)的更多相关文章
- hihoCoder 1432 : JiLi Number(吉利数)
hihoCoder #1432 : JiLi Number(吉利数) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - 题目描述 Driver Ji l ...
- 2道acm编程题(2014):1.编写一个浏览器输入输出(hdu acm1088);2.encoding(hdu1020)
//1088(参考博客:http://blog.csdn.net/libin56842/article/details/8950688)//1.编写一个浏览器输入输出(hdu acm1088)://思 ...
- 1117 Eddington Number (25 分)
1117 Eddington Number (25 分) British astronomer Eddington liked to ride a bike. It is said that in o ...
- 1038 Recover the Smallest Number (30 分)
1038 Recover the Smallest Number (30 分) Given a collection of number segments, you are supposed to r ...
- 1019 General Palindromic Number (20 分)
1019 General Palindromic Number (20 分) A number that will be the same when it is written forwards or ...
- [PAT] 1144 The Missing Number(20 分)
1144 The Missing Number(20 分) Given N integers, you are supposed to find the smallest positive integ ...
- 数据类型总结——Number(数值类型)
相关文章 简书原文:https://www.jianshu.com/p/9fb573ef10da 数据类型总结——概述:https://www.cnblogs.com/shcrk/p/9266015. ...
- 数据库number(4,3)表示什么
1 你看 number(4,3)是表示 这个数 一共有4位是有效位,后面的3 表示有3个是小数也就是这个数 只能是1.234,这样格式的 最大只能是9.999,2 number(3,4) 表示这个数 ...
- The Luckiest number(hdu2462)
The Luckiest number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
随机推荐
- window.addEventListener介绍说明
原型 public override function addEventListener(type:String, listener:Function, useCapture:Boolean = fa ...
- win10中打开SQL Server 2008 的SQL Server配置管理器方法
win10找不到SQL Server配置管理器 搜索 SQLServerManager10.msc,或者运行文件:“C:\Windows\SysWOW64\SQLServerManager10.msc ...
- 01_1_jdom调用xml文件
01_1_jdom调用xml文件 1. 导入jdom.jar包 2. xml文件内容 test.xml <?xml version="1.0" encoding=" ...
- 【转】VS2010下MFC的串口编程
串口通信简介 一般来说,计算机都有一个或多个串行端口,这些串口提供了外部设备与PC进行数据传输和通信的通道,在CPU和外设之间充当解释器的角色.当字符数据从CPU发送给外设时,这些字符数据将被转换成串 ...
- 【转】C++后台开发应该读的书
转载自http://www.cnblogs.com/balloonwj/articles/9094905.html 作者 左雪菲 根据我的经验来谈一谈,先介绍一下我的情况,坐标上海,后台开发(也带团队 ...
- 【莫队】bzoj4542: [Hnoi2016]大数
挺有意思的,可以仔细体味一下的题:看白了就是莫队板子. Description 小 B 有一个很大的数 S,长度达到了 N 位:这个数可以看成是一个串,它可能有前导 0,例如00009312345.小 ...
- Python爬虫系列-Urllib库详解
Urllib库详解 Python内置的Http请求库: * urllib.request 请求模块 * urllib.error 异常处理模块 * urllib.parse url解析模块 * url ...
- python学习之判断和循环的使用
作为一个小白运维,工作中常常发现很多东西还是自动化的好一点,所以就想到的用python来编写脚本.当然,我肯定是不会的啦,哈哈哈~~~~所以啦,身为一个懒癌晚期的上班族不得不在闲余时间来好好学学pyt ...
- 2-python基础
1.第一个程序 新建一个python文件,然后写上代码,运行即可 print("hello world") 2.变量 变量就是存东西,供后面来用的 变量名只能是 字母.数字或下划线 ...
- python基本操作(五)
if 判断 if 条件: 代码1 代码2 代码3 代码块(同一缩进级别的代码,例如代码1.代码2和代码3是相同缩进的代码,这三个代码组合在一起就是一个代码块,相同缩进的代码会自上而下的运行) cls ...