题意:

给一个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的应用的更多相关文章

  1. POJ3696:The Luckiest number(欧拉函数||求某数最小的满足题意的因子)

    Chinese people think of '8' as the lucky digit. Bob also likes digit '8'. Moreover, Bob has his own ...

  2. 【P2158】仪仗队&欧拉函数详解

    来一道数论题吧. 这个题一眼看上去思路明确,应该是数论,但是推导公式的时候却出了问题,根本看不出来有什么规律.看了马佬题解明白了这么个规律貌似叫做欧拉函数,于是就去百度学习了一下这东西. 欧拉函数的含 ...

  3. POJ 3696 The Luckiest number (欧拉函数,好题)

    该题没思路,参考了网上各种题解.... 注意到凡是那种11111..... 22222..... 33333.....之类的序列都可用这个式子来表示:k*(10^x-1)/9进而简化:8 * (10^ ...

  4. POJ 2478 Farey Sequence(欧拉函数前n项和)

    A - Farey Sequence Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  5. poj 2480 Longge's problem [ 欧拉函数 ]

    传送门 Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7327   Accepted: 2 ...

  6. poj 3090 &amp;&amp; poj 2478(法雷级数,欧拉函数)

    http://poj.org/problem?id=3090 法雷级数 法雷级数的递推公式非常easy:f[1] = 2; f[i] = f[i-1]+phi[i]. 该题是法雷级数的变形吧,答案是2 ...

  7. POJ 2407:Relatives(欧拉函数模板)

    Relatives AC代码 Relatives Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16186   Accept ...

  8. POJ 2478 线性递推欧拉函数

    题意: 求sigma phi(n) 思路: 线性递推欧拉函数 (维护前缀和) //By SiriusRen #include <cstdio> using namespace std; # ...

  9. 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 ...

随机推荐

  1. PHP程序员的简单运维

    所谓的简单运维就是保证自己开发的程序能正常运行和使用. 当一个程序员需要兼作运维时候需要掌握以下技能 1.linux系统基础命令和Windows Server操作 是基础中的基础,ls, rm, to ...

  2. npm命令要记

    npm list - depth 0 查看依赖 cnpm install 安装 npm outdated 查看模块过时 npm cache clear

  3. 树链剖分【CF343D】Water Tree

    Description Mad scientist Mike has constructed a rooted tree, which consists of nnvertices. Each ver ...

  4. 【PKUSC 2015】的一道数学题

    有9个人,每三个人中至少有两个互相认识,求证这里面至少有4个人互相认识 PKU官方题解: 引理:二染色K6中一定有同色K3. 证明:考虑某一个点,它一定连出至少三条同色边(不妨设为红边),这三条边连的 ...

  5. 【贪心】Gym - 100507H - Pair: normal and paranormal

    每次取相邻的两个可以射击的从序列中删除,重复n次. 可以看作括号序列的匹配. #include<cstdio> #include<vector> using namespace ...

  6. 【线段树】bzoj3922 Karin的弹幕

    设置一个值K. d<=K:建立多组线段树:d>K:暴力. 最优时间复杂度的伪计算: O(n*K*logn(建树)+m*logn(询问类型1)+m*n/K(询问类型2)+m*K*logn(修 ...

  7. 【左偏树】BZOJ2809-[APIO2012]dispatching

    [题目大意] 在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿.在这个帮派里,有一名忍者被称之为 Master.除了 Master以外,每名忍者都有且仅有一个上级.为保密,同 ...

  8. 1.5(java学习笔记)this关键字

    this关键字主要有三个作用 1.调用本类中的属性. public class TextThis { public static void main(String[] args){ Person p1 ...

  9. 1.1(java学习笔记) 面向过程与面向对象

    面向过程思考时,我们会先思考具体的步骤,第一步走什么,第二步做什么. 比如电脑新建文件夹,第一步:打开电脑 第二步:按下鼠标右键. 第三步:找到新建选项 第四步:点击新建选项下的文件夹 c语言是典型的 ...

  10. Exercise01_03

    public class TuAn{ public static void main(String[] args){ System.out.println(" J A V V A" ...