题意:

给一个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. Redis 源码走读(一)事件驱动机制与命令处理

    eventloop 从 server.c 的 main 方法看起 int main(int argc, char **argv) { ....... aeSetBeforeSleepProc(serv ...

  2. 【转】appium常用方法整理

    1.相对坐标解锁九宫格 应用场景 QQ解锁屏幕如上,可见九个按键在同一个View下面,要实现解锁,用press   moveTo  release  perform方法 实现代码如下: WebElem ...

  3. 【转】SonarQube配置自定义的CheckStyle代码规则

    原文地址:https://www.jianshu.com/p/ff1d800885ce 惯例第一步肯定是SonarQube的安装与运行配置了,但这部分不在本文主题内,网上一搜一大把,这里就不讲了,大家 ...

  4. (21)python Anaconda

    1.安装 Anaconda下载镜像      --官网下载太慢 https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/ 下载安装后 2.添加第三方源 管 ...

  5. 2017中南大学暑期集训day1 : debug&STL-A

    A - Surprising Strings 题意就是给你一个字符串,例如ZGBG,有一种称谓叫D-unique 这个字符串 在D=0时, 有三个子串 ZG GB BG,因为这三个都不同,也就是uni ...

  6. tarjan算法与无向图的连通性(割点,桥,双连通分量,缩点)

    基本概念 给定无向连通图G = (V, E)割点:对于x∈V,从图中删去节点x以及所有与x关联的边之后,G分裂为两个或两个以上不相连的子图,则称x为割点割边(桥)若对于e∈E,从图中删去边e之后,G分 ...

  7. 训练指南 UVALive - 5135 (双连通分量)

    layout: post title: 训练指南 UVALive - 5135 (双连通分量) author: "luowentaoaa" catalog: true mathja ...

  8. git log 查看某文件的修改历史

    先进入此文件所在的目录下 1. git log --help 所有的git命令都可以通过git manual查看 在synopsis中可以看到公式  git log [<options>] ...

  9. Eclipse导入idea 项目

    学校做的项目老师会导入到Eclipse下查看. 使用idea做的项目直接导入eclipse会发生问题(file-Export to Eclipse) 让Eclipse兼容idea项目,或者直接导入id ...

  10. 【分类讨论】bzoj3856 Monster

    #include<cstdio> using namespace std; int T=0; long long h,a,b,k; int main() { freopen("b ...