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 ...
随机推荐
- tomcat中reloadable作用
reloadable作用 reloadable:如果这个属性设为true,tomcat服务器在运行状态下会监视在WEB-INF/classes和WEB-INF/lib目录下class文件的改动,如果监 ...
- CF 1003C Intense Heat【前缀和/精度/双层暴力枚举】
The heat during the last few days has been really intense. Scientists from all over the Berland stud ...
- POJ 2438 Children's Dining(哈密顿回路)
题目链接:http://poj.org/problem?id=2438 本文链接:http://www.cnblogs.com/Ash-ly/p/5452615.html 题意: 有2*N个小朋友要坐 ...
- 福州三中集训day4
第6天写第4天的博客….可以说是很弱了…… 讲了一天的高级数据结构,可以说很迷,先是并查集,然后是树状数组,线段树,MAP函数,KMP算法. 很难……确实不是很清楚…但是很重要,回去以后这应该说是优先 ...
- Java的ClassLoader机制
http://blog.chenlb.com/2009/06/java-classloader-architecture.html http://blog.csdn.net/lovingprince/ ...
- 【博弈论】【SG函数】【枚举】bzoj1188 [HNOI2007]分裂游戏
因为第i个瓶子里的所有豆子都是等价的,设sg(i)表示第i个瓶子的sg值,可以转移到sg(j)^sg(k)(i<j<n,j<=k<n)的状态. 只需要考虑豆子数是奇数的瓶子啦, ...
- 【单调队列】bzoj2096 [Poi2010]Pilots
用两个单调队列维护序列中的最大值和最小值即可. poi~ #include<cstdio> #include<algorithm> using namespace std; i ...
- [CF842E]Nikita and game
[CF842E]Nikita and game 题目链接: CF842E 博客地址: [CF842E]Nikita and game - skylee 题目大意: 一棵树初始只有一个编号为\(1\)的 ...
- 1.5(Spring MVC学习笔记) 拦截器(Interceptor)
一.拦截器 1.1拦截器简介 Spring中的拦截器类似Servlet中的过滤器(Filter),主要用于拦截用户请求, 并进行一定的处理操作(如验证权限.记录日志.设置编码方式等). 1.2拦截器实 ...
- NPOI读取Excel2003,2007
using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Lin ...