传送门

Solution

懒得写啦

Code

 #include<iostream>
#include<cstdio>
#include<cmath>
#define Rg register
#define go(i,a,b) for(Rg int i=a;i<=b;i++)
#define yes(i,a,b) for(Rg int i=a;i>=b;i--)
#define ll long long
using namespace std;
int read()
{
int x=,y=;char c=getchar();
while(c<''||c>''){if(c=='-')y=-;c=getchar();}
while(c>=''&&c<=''){x=(x<<)+(x<<)+c-'';c=getchar();}
return x*y;
}
ll T,L,d,n,m,ans,c;
bool flag=;
ll gcd(ll x,ll y){return y==?x:gcd(y,x%y);}
ll phi(ll x)
{
ll sm=x,y=x;
go(i,,sqrt(y))
{
if(x%i==)sm=sm/i*(i-);
while(x%i==)x/=i;
}
if(x>)sm=sm/x*(x-);
return sm;
}
ll mul(ll x,ll y,ll mod)
{
ll sm=;
while(y)
{
if(y&)sm=(sm+x)%mod;
x=(x<<)%mod;y>>=;
}
return sm;
}
ll ksm(ll x,ll y,ll mod)
{
ll sm=;
while(y)
{
if(y&)sm=mul(sm,x,mod);//注意这里直接乘起来会溢出
x=mul(x,x,mod);y>>=;
}
return sm;
}
int main()
{
while()
{
scanf("%lld",&L);if(!L)break;T++;flag=;ans=;
if(%L==){printf("Case %lld: 1\n",T);continue;}
d=gcd(L,);n=*L/d;m=phi(n);c=sqrt(m);
go(i,,c)
{
if(m%i==&&ksm(,i,n)==){ans=i;flag=;break;}
}
if(!flag)
yes(i,c,)
{
if(m%i==&&ksm(,m/i,n)==){ans=m/i;break;}
}
printf("Case %lld: %lld\n",T,ans);
}
return ;
}

Poj3696 The Lukiest Number的更多相关文章

  1. POJ3696 The Luckiest number

    题意 Language:Default The Luckiest number Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7 ...

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

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

  3. [POJ3696]The Luckiest number(数论)

    题目:http://poj.org/problem?id=3696 题意:给你一个数字L,你要求出一个数N,使得N是L的倍数,且N的每位数都必须是8,输出N的位数(如果不存在输出0) 分析: 首先我们 ...

  4. POJ3696 The Luckiest Number 欧拉定理

    昨天终于把欧拉定理的证明看明白了...于是兴冲冲地写了2道题,发现自己啥都不会qwq 题意:给定一个正整数L<=2E+9,求至少多少个8连在一起组成正整数是L的倍数. 这很有意思么... 首先, ...

  5. 「POJ3696」The Luckiest number【数论,欧拉函数】

    # 题解 一道数论欧拉函数和欧拉定理的入门好题. 虽然我提交的时候POJ炸掉了,但是在hdu里面A掉了,应该是一样的吧. 首先我们需要求的这个数一定可以表示成\(\frac{(10^x-1)}{9}\ ...

  6. JavaScript Math和Number对象

    目录 1. Math 对象:数学对象,提供对数据的数学计算.如:获取绝对值.向上取整等.无构造函数,无法被初始化,只提供静态属性和方法. 2. Number 对象 :Js中提供数字的对象.包含整数.浮 ...

  7. Harmonic Number(调和级数+欧拉常数)

    题意:求f(n)=1/1+1/2+1/3+1/4-1/n   (1 ≤ n ≤ 108).,精确到10-8    (原题在文末) 知识点:      调和级数(即f(n))至今没有一个完全正确的公式, ...

  8. Java 特定规则排序-LeetCode 179 Largest Number

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  9. Eclipse "Unable to install breakpoint due to missing line number attributes..."

    Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...

随机推荐

  1. python 模块之-sys

    python 模块 sys import sys sys.argv       # 参数,第一个参数是脚本的文件明,自定义参数为数组的第二个   sys.argv[1] sys.version   # ...

  2. Hopcroft-Carp 算法模板 自用

    #include <iostream> #include <cstdio> #include <cstring> #include <queue> #d ...

  3. mysql case when 判断null

    select  name,case WHEN m.NAME is null THEN '' else m.NAME end NAME1 from  sys_users

  4. mysql中存储过程

    存储过程procedure 存储过程,其本质还是函数——但其规定:不能有返回值: 定义形式: 说明: 1,in:用于设定该变量是用来“接收实参数据”的,即“传入”:默认不写,就是in 2,out:用于 ...

  5. luogu1169 棋盘制作 (单调栈)

    先预处理出来从每个位置 以0开始 往右交替最多能放多少格 然后就相当于对每一列做HISTOGRA #include<bits/stdc++.h> #define pa pair<in ...

  6. Windows 10 MBR转GPT

    Windows 10的创意者更新中,新增了mbr2gpt命令行工具,只需简单几步快速搞定分区表的转换 语法 MBR2GPT /validate|convert [/disk:] [/logs:] [/ ...

  7. Ubuntu安装Atom编辑器

    安装方法 执行以下命令 sudo add-apt-repository ppa:webupd8team/atom sudo apt-get update udo apt-get install ato ...

  8. 关于打包测试环境,百度地图报 Bmap not undefined

    https的网站使用百度地图,如果你引用的地址没写对的话,加载不出来百度地图,被认为是不安全的JS内容. https://api.map.baidu.com/api?+你的秘钥+&s=1 应该 ...

  9. centos7 上配置Javaweb---MySQL的安装与配置、乱码解决

    上一篇谢了关于jdk和tomcat的安装.今天先更新一下有用的. 1. 不用关闭防火墙,把80端口添加进防火墙的开放端口. firewall-cmd --zone=public --add-port= ...

  10. 20145215《网络对抗》Exp7 网络欺诈技术防范

    20145215<网络对抗>Exp7 网络欺诈技术防范 基础问题回答 通常在什么场景下容易受到DNS spoof攻击? 在同一局域网下比较容易受到DNS spoof攻击,攻击者可以冒充域名 ...