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 ...
随机推荐
- Ubuntu下命令行访问网站
第一步,需要安装一个名为w3m的软件工具,打开终端,输入如下命令 sudo apt-get install w3m 第二步,安装好w3m之后,在终端里面启动w3m,打开一个网址,比如w3m www ...
- 解决cocos simpleAudioEngine播放mp3失败问题
今天用cocos3.x版本实现游戏音乐播放发现一个坑,策划发来的mp3格式音频,用 simpleAudioEngine无法播放, 以为是路径问题,断点调试没找到,然后拷贝了cocos自带的mp3音频文 ...
- Vue路由跳转到新页面时 默认在页面最底部 而不是最顶部 的解决
今天碰到一个问题 vue路由跳转到新的页面时会直接显示页面最底部 正常情况下是显示的最顶部的 而且好多路由中不是全部都是这种情况 折腾好长时间也没解决 最后在网上找到了解决办法 其实原理很 ...
- Flask-蓝图、模型与CodeFirst
一.应用.蓝图与视图函数 结构,如图: Flask最上层是app核心对象 ,在这个核心对象上可以插入很多蓝图,这个蓝图是不能单独存在的,必须将app作为插板插入app ,在每一个蓝图上,可以注册很多静 ...
- 利用wget 和 curl 监控网站是否正常
监控网站URL是否正常最常见的方法莫过于wget和curl命令了,这两个命令都是非常强大,参数也非常多,下面列举几个常用的参数. wget 常用命令参数:--spider ...
- 中移物联网onenet入门学习笔记1:资料获取
onenet学习资料.视频.例程汇总:https://open.iot.10086.cn/bbs/thread-977-1-1.html onenet开发文档:https://open.iot.100 ...
- org.apache.catalina.webresources.Cache.backgroundProcess The background cache eviction process was unable to free [10] percent of the cache for Context [/filestore] - consider increasing the maximum s
需要耐心啊,太急于求成,希望直接就得到解决方法了...以至于正确方法都已经出现了,我却没有耐心看下去,所以反而又耽误了不少时间.... 项目加载100+张图片,还有一个小的MP4,所以console警 ...
- 【Open-Falcon】Linux下安装Open-Falcon
一.Open-Falcon组件简述 [Open-Falcon绘图相关组件] Agent: 部署在目标机器采集机器监控项 Transfer : 数据接收端,转发数据到后端Graph和Judge Gra ...
- loj2254 「SNOI2017」一个简单的询问
ref #include <algorithm> #include <iostream> #include <cstdio> #include <cmath& ...
- webpack 环境搭建+实现热更新
让我们一起构建一个小的app 为了便于你更好的了解Webpack带来的好处,我们将会构建一个非常小的app并将资源文件打包.在这个教程中我推荐基于Node4或Node5和NPM3来进行开发,这样就避免 ...