传送门

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. cxf Webservice 使用httpClient 调用

    package com.wistron.wh.swpc.portal.uitl; import java.io.BufferedInputStream;import java.io.File;impo ...

  2. mysql5.7 rpm安装教程

    注意版本和此次更新时间 2017-12-03  版本:mysql-5.7.20-1.el6.x86_64  环境:linux6.x ​官方下载地址: wget https://dev.mysql.co ...

  3. instanceof判断的对象可以是接口

    instanceof是Java的一个二元操作符(运算符) 用法 boolean result = object instanceof class instanceof通过返回一个布尔值来指出,这个对象 ...

  4. 洛谷UVA12995 Farey Sequence(欧拉函数,线性筛)

    洛谷题目传送门 分数其实就是一个幌子,实际上就是求互质数对的个数(除开一个特例\((1,1)\)).因为保证了\(a<b\),所以我们把要求的东西拆开看,不就是\(\sum_{i=2}^n\ph ...

  5. 用ip代替机器名访问sharepoint 站点

    1. aam 里加入一个ip的internet 2. iis里不用加上ip,但不要有host name   出现的问题: 1. 当打开站点里会出现这个错误 file not found 2. 当加授予 ...

  6. PKUWC 2019 记

     “连剑都插在了地上,可是我不应该就这么承认失败,想要到达山顶的人,不应该在山脚下就倒下啊” Day -5 (2019.1.15) 学考结束了,文化课暂停一段.早上飞机前往中山纪念中学.纪中好大呀,果 ...

  7. android + eclipse + 后台静默安装(一看就会)

      首先要说到三个类. import android.content.pm.IPackageInstallObserver; import android.content.pm.IPackageIns ...

  8. change username on ubuntu.

    Below tutorial will show you how to change username in ubuntu 12.04 precise.First,we need login as r ...

  9. A1033. To Fill or Not to Fill

    With highways available, driving a car from Hangzhou to any other city is easy. But since the tank c ...

  10. hdu 1756(判断点是否在多边形中)

    传送门 题解: 射线法判定点是否在多边形内部: AC代码: #include<iostream> #include<cstdio> #include<cmath> ...