POJ3696 The Luckiest Number 欧拉定理
昨天终于把欧拉定理的证明看明白了。。。于是兴冲冲地写了2道题,发现自己啥都不会qwq
题意:给定一个正整数L<=2E+9,求至少多少个8连在一起组成正整数是L的倍数。
这很有意思么。。。
首先,连续的8可表示为:8*(10^x-1)/9;
那么就是L|8*(10^x-1)/9 => 9*L|8*(10^x-1) ,求最小的x;
我们设d=gcd(L,8)
则9*L/d | 8/d*(10^x-1),因为此时9*L/d 和 8/d 互质,所以9*L/d | 10^x-1,所以 10^x ≡ 1 (mod 9*L/d);
然后要证明一个结论:a^x ≡ 1 (mod n)的最小正整数解x0能整除φ(n)
证明:
反证:设不能整除,则设φ(n)=q*x0+r;(1<=r<x0)
因为a^x0 ≡ 1 (mod n),所以a^(q*x0) ≡ 1(mod n)
又因为a^φ(n) ≡ 1 (mod n),所以a^r ≡ 1 (mod n)
因为r<x0,所以假设不成立;
证毕。
所以我们枚举每个φ(9*L/d) 的约数,用快速幂判断就好了。
#include<cstdio>
#include<iostream>
#include<algorithm>
#define ll long long
#define R register ll
using namespace std;
inline ll g() {
R ret=,fix=; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-:fix;
do ret=ret*+(ch^); while(isdigit(ch=getchar())); return ret*fix;
}
ll a[],n,ans;
inline ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
inline ll phi(ll n) {
R m=n; for(R i=;i*i<=n;++i) if(n%i==) {
m=m/i*(i-);
while(n%i==) n/=i;
} if(n>) m=m/n*(n-); return m;
}
inline ll mul(ll a,ll b) {
a%=n,b%=n; R c=(long double)a*b/n;
R ans=a*b-c*n; if(ans<) ans+=n;
if(ans>=n) ans-=n; return ans;
}
inline ll qpow(ll a,ll p) { R ret=;
for(;p;p>>=,a=mul(a,a)) if(p&) ret=mul(ret,a); return ret;
}
signed main() { R t=;
while(n=g(),n!=) { //cout<<n<<endl;
n=*n/gcd(,n);
printf("Case %d: ",++t);
if(gcd(,n)==) {
R p=phi(n),cnt=; //cout<<"PHI: "<<p<<endl;
for(R i=;i*i<=p;++i) if(p%i==) {
a[++cnt]=i;
if(i*i!=p) a[++cnt]=p/i;
} sort(a+,a+cnt+); R i;
for(i=;i<=cnt;++i) if(qpow(,a[i])==) break;
printf("%lld\n",a[i]);
} else printf("0\n");
}
}
2019.05.11
POJ3696 The Luckiest Number 欧拉定理的更多相关文章
- POJ3696 The Luckiest number
题意 Language:Default The Luckiest number Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7 ...
- POJ3696:The Luckiest number(欧拉函数||求某数最小的满足题意的因子)
Chinese people think of '8' as the lucky digit. Bob also likes digit '8'. Moreover, Bob has his own ...
- [POJ3696]The Luckiest number(数论)
题目:http://poj.org/problem?id=3696 题意:给你一个数字L,你要求出一个数N,使得N是L的倍数,且N的每位数都必须是8,输出N的位数(如果不存在输出0) 分析: 首先我们 ...
- POJ_3696 The Luckiest number 【欧拉定理+同余式+对取模的理解】
一.题目 Chinese people think of '8' as the lucky digit. Bob also likes digit '8'. Moreover, Bob has his ...
- poj 3696 The Luckiest Number
The Luckiest Number 题目大意:给你一个int范围内的正整数n,求这样的最小的x,使得:连续的x个8可以被n整除. 注释:如果无解输出0.poj多组数据,第i组数据前面加上Case ...
- poj_3696_The Luckiest number
Chinese people think of '8' as the lucky digit. Bob also likes digit '8'. Moreover, Bob has his own ...
- HDU 2462 The Luckiest number
The Luckiest number Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Ori ...
- The Luckiest number(hdu2462)
The Luckiest number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- 「POJ3696」The Luckiest number【数论,欧拉函数】
# 题解 一道数论欧拉函数和欧拉定理的入门好题. 虽然我提交的时候POJ炸掉了,但是在hdu里面A掉了,应该是一样的吧. 首先我们需要求的这个数一定可以表示成\(\frac{(10^x-1)}{9}\ ...
随机推荐
- Linux编程之错误代码
头文件/usr/include/asm-generic/errno-base.h定义错误码: #ifndef _ASM_GENERIC_ERRNO_BASE_H #define _ASM_GENERI ...
- org.springframework.web.client.HttpClientErrorException: 400 null
异常代码: org.springframework.web.client.HttpClientErrorException: 400 null 已解决. 百度了一下400代表无法解析请求. 说明请求是 ...
- 关于日志类Log4j的使用
log4j 的配置 #下面定义日志输出级别是 INFO,并且配置了2个输出目的地,一个是A3,一个是console log4j.rootLogger = INFO,A3,CONSOLE #日志最低的输 ...
- TS学习之枚举
使用枚举可以定义一些有名字的数字常量 enum Test{ one = 1, two, three, four } console.log(Test); /*{ '1': 'one', '2': 't ...
- Jenkins搭建Nodejs自动化测试
一.安装Jenkins(Windows) 1. 在Jenkins官网(https://jenkins.io/)下载安装包,解压并安装 2. 安装完成后,会自动打开一个页面,根据提示在安装目录下找到随机 ...
- hive 连接查询sql对比效率
准备4个表 从mysql 导出excel 转换为txt 创建hive 表的导入文件 create table bdqn_student( sno int, sname string, sbirthda ...
- jprofiler9.1.1 安装与配置
一.安装部分 安装包: 1.jprofiler_linux_9_1_1.rpm 2.jprofiler_windows-x64_9_1_1.exe 需要注意的是,Linux 和 Windows 安装的 ...
- 关闭socket以及Socket选项
1 关闭socket ·1)socket套接字使用完毕之后,我们需要将起及时的关闭,正如输入输出流的关闭是一样的:在我上一篇文章中介绍了如何模拟httpClient发送请求数据:这里我还是使用上一篇文 ...
- @Deprecated使用技巧
本文转自 http://www.cnblogs.com/hzhuxin/p/4645070.html 我们在做项目时,前期写的类中的一些代码可能由于需求变化的原因需要重写,有时重写时方法的传参和返回值 ...
- hbase->Mapreduce->hbase
Hbase对Mapreduce API进行了扩展,方便Mapreduce任务读写HTable数据. package taglib.customer; import java.io.IOExceptio ...