poj 3696 The Luckiest number 欧拉函数在解a^x=1modm的应用
题意:
给一个L,求长度最小的全8数满足该数是L的倍数。
分析:
转化为求方程a^x==1modm。
之后就是各种数学论证了。
代码:
//poj 3696
//sep9
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
ll L;
ll factor[65536]; ll mul(ll x,ll y,ll p)
{
ll ret=0;
while(y){
if(y&1)
ret=(ret+x)%p;
x=(x+x)%p;
y>>=1;
}
return ret;
} ll pow(ll x,ll n,ll m)
{
ll ret=1;
x%=m;
while(n){
if(n&1)
ret=mul(ret,x,m);
x=mul(x,x,m);
n>>=1;
}
return ret;
} ll euler(ll n)
{
ll ret=n;
for(ll i=2;i*i<=n;++i)
if(n%i==0){
ret=ret/i*(i-1);
while(n%i==0)
n/=i;
}
if(n>1)
ret=ret/n*(n-1);
return ret;
} ll cal()
{
ll m=L*9;
for(int i=0;i<3;++i)
if(m%2==0)
m/=2;
else
break;
if(m%2==0||m%5==0)
return 0;
ll phi=euler(m);
int idx=0;
for(ll i=1;i*i<=phi;++i)
if(phi%i==0)
factor[idx++]=i,factor[idx++]=phi/i;
sort(factor,factor+idx);
for(int i=0;i<idx;++i)
if(pow(10,factor[i],m)==1)
return factor[i];
} int main()
{
int cases=0;
while(scanf("%I64d",&L)==1&&L){
printf("Case %d: ",++cases);
printf("%I64d\n",cal());
}
return 0;
}
poj 3696 The Luckiest number 欧拉函数在解a^x=1modm的应用的更多相关文章
- POJ3696:The Luckiest number(欧拉函数||求某数最小的满足题意的因子)
Chinese people think of '8' as the lucky digit. Bob also likes digit '8'. Moreover, Bob has his own ...
- 【P2158】仪仗队&欧拉函数详解
来一道数论题吧. 这个题一眼看上去思路明确,应该是数论,但是推导公式的时候却出了问题,根本看不出来有什么规律.看了马佬题解明白了这么个规律貌似叫做欧拉函数,于是就去百度学习了一下这东西. 欧拉函数的含 ...
- POJ 3696 The Luckiest number (欧拉函数,好题)
该题没思路,参考了网上各种题解.... 注意到凡是那种11111..... 22222..... 33333.....之类的序列都可用这个式子来表示:k*(10^x-1)/9进而简化:8 * (10^ ...
- POJ 2478 Farey Sequence(欧拉函数前n项和)
A - Farey Sequence Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- poj 2480 Longge's problem [ 欧拉函数 ]
传送门 Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7327 Accepted: 2 ...
- poj 3090 && poj 2478(法雷级数,欧拉函数)
http://poj.org/problem?id=3090 法雷级数 法雷级数的递推公式非常easy:f[1] = 2; f[i] = f[i-1]+phi[i]. 该题是法雷级数的变形吧,答案是2 ...
- POJ 2407:Relatives(欧拉函数模板)
Relatives AC代码 Relatives Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16186 Accept ...
- POJ 2478 线性递推欧拉函数
题意: 求sigma phi(n) 思路: 线性递推欧拉函数 (维护前缀和) //By SiriusRen #include <cstdio> using namespace std; # ...
- POJ 2480 Longge's problem 欧拉函数—————∑gcd(i, N) 1<=i <=N
Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6383 Accepted: 2043 ...
随机推荐
- 在Ubuntu 16.04安装 Let’s Encrypt并配置ssl
1.安装前准备 1)要确保python的默认版本为2.7及以上版本. 2)需要配置的apache.nginx需要提前配置绑定域名. 2.安装ssl 在这个https://certbot.eff.org ...
- 【NppExec】直接在notepad++运行python的插件:NppExec
1.下载NppExec http://sourceforge.net/projects/npp-plugins/files/NppExec/ 2.安装 解压,全部复制到d:/program ...
- python数据转换工具Into
转:http://python.jobbole.com/81564/ 再次介绍Into包:整洁地数据迁移 2015/03/12 · 基础知识 · into, 数据迁移 分享到:3 本文由 伯乐在线 ...
- HDU 5935 Car【贪心,枚举,精度】
Problem Description Ruins is driving a car to participating in a programming contest. As on a very t ...
- POJ 2488 A Knight's Journey (回溯法 | DFS)
题目链接:http://poj.org/problem?id=2488 题意: 在国际象棋的题盘上有一个骑士,骑士只能走“日”,即站在某一个位置,它可以往周围八个满足条件的格子上跳跃,现在给你一个p ...
- CSS选择符——分门别类
CSS选择符--分门别类 有时候,老是会对一些CSS选择器模模糊糊,傻傻分不清.今天花了点时间整理了一下,感觉世界清静了不少. 用XMIND做出了思维导图: 主要有11中选择器:元素.类ID.后代.子 ...
- Xamarin XAML语言教程ContentView视图作为自定义视图的父类
Xamarin XAML语言教程ContentView视图作为自定义视图的父类 自定义视图的父类:ContentView视图可以作为自定义视图的父类. [示例14-2]以下将自定义一个颜色视图.具体的 ...
- mysql实现full outer join
由于MySQL设计时不支持full outer join, 所以如果有全连接需求时,需要一点小技巧来实现. 假设有两个表t1,t2 full outer join 的效果和下面的效果一样: SELEC ...
- 【母函数】hdu2082 找单词
普通型母函数详解见这里:http://www.wutianqi.com/?p=596 裸题,存个板子. #include<cstdio> #include<cstring> u ...
- 6.5(java学习笔记)其他流(字节数组流,数据流,对象流,打印流)
一.字节数组流 之前使用输入输出流的操作的对象是文件,而这里字节数组流操作的对象是内存,内存可以看做是一个字节数组. 使用字节数组流读写就可以看做是从内存A到内存B的读写,对象时内存即字节数组. 1. ...