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 ...
随机推荐
- javaweb基础(13)_session防止表单重复提交
在平时开发中,如果网速比较慢的情况下,用户提交表单后,发现服务器半天都没有响应,那么用户可能会以为是自己没有提交表单,就会再点击提交按钮重复提交表单,我们在开发中必须防止表单重复提交. 一.表单重复提 ...
- JDBC连接数据库报错:java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. ......
问题:Java程序使用JDBC连接MySQL数据库时,控制台报错如下: java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' ...
- 53. Maximum Subarray@python
Given an integer array nums, find the contiguous subarray (containing at least one number) which has ...
- Confirm the Ending--freecodecamp算法题目
Confirm the Ending(检查字符串结尾) 要求 判断一个字符串(str)是否以指定的字符串(target)结尾. 如果是,返回true;如果不是,返回false. 思路 利用.repla ...
- Mac配置gdb的一些问题
1.Unable to find Mach task port for process-id 1527: (os/kern) failure (0x5). (please check gdb is ...
- ccf 201712-2 游戏(Python实现)
一.原题 问题描述 试题编号: 201712-2 试题名称: 游戏 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 有n个小朋友围成一圈玩游戏,小朋友从1至n编号,2号小朋友坐 ...
- python3爬取”理财大视野”中的股票,并分别写入txt、excel和mysql
需求:爬取“理财大视野”网站的排名.代码.名称.市净率.市盈率等信息,并分别写入txt.excel和mysql 环境:python3.6.5 网站:http://www.dashiyetouzi.co ...
- LeetCode(228) Summary Ranges
题目 Given a sorted integer array without duplicates, return the summary of its ranges. For example, g ...
- LeetCode(189) Rotate Array
题目 Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the arr ...
- 10个MCU常用的基础知识
转自:http://bbs.21ic.com/icview-2659278-1-1.html 1.MCU有串口外设的话,在加上电平转换芯片,如MAX232.SP3485就是RS232和RS485接口了 ...