Poj3696 The Lukiest Number
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的更多相关文章
- POJ3696 The Luckiest number
题意 Language:Default The Luckiest number Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7 ...
- POJ3696:The Luckiest number(欧拉函数||求某数最小的满足题意的因子)
Chinese people think of '8' as the lucky digit. Bob also likes digit '8'. Moreover, Bob has his own ...
- [POJ3696]The Luckiest number(数论)
题目:http://poj.org/problem?id=3696 题意:给你一个数字L,你要求出一个数N,使得N是L的倍数,且N的每位数都必须是8,输出N的位数(如果不存在输出0) 分析: 首先我们 ...
- POJ3696 The Luckiest Number 欧拉定理
昨天终于把欧拉定理的证明看明白了...于是兴冲冲地写了2道题,发现自己啥都不会qwq 题意:给定一个正整数L<=2E+9,求至少多少个8连在一起组成正整数是L的倍数. 这很有意思么... 首先, ...
- 「POJ3696」The Luckiest number【数论,欧拉函数】
# 题解 一道数论欧拉函数和欧拉定理的入门好题. 虽然我提交的时候POJ炸掉了,但是在hdu里面A掉了,应该是一样的吧. 首先我们需要求的这个数一定可以表示成\(\frac{(10^x-1)}{9}\ ...
- JavaScript Math和Number对象
目录 1. Math 对象:数学对象,提供对数据的数学计算.如:获取绝对值.向上取整等.无构造函数,无法被初始化,只提供静态属性和方法. 2. Number 对象 :Js中提供数字的对象.包含整数.浮 ...
- Harmonic Number(调和级数+欧拉常数)
题意:求f(n)=1/1+1/2+1/3+1/4-1/n (1 ≤ n ≤ 108).,精确到10-8 (原题在文末) 知识点: 调和级数(即f(n))至今没有一个完全正确的公式, ...
- Java 特定规则排序-LeetCode 179 Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- Eclipse "Unable to install breakpoint due to missing line number attributes..."
Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...
随机推荐
- iTunes 12.7 没有应用程序选项了,重新安装iTunes 12.6.3
iTunes 12.6.3 下载地址: Mac http://t.cn/RO5rIfE Win 32 http://t.cn/ROtta1T Win64 http://t.cn/ROtta1n 安装好 ...
- 睡前小dp-hdu3853-概率dp
http://acm.hdu.edu.cn/showproblem.php?pid=3853 膜猴烧酒madoka 讲定义为dp[i][j] 位置为ij的魔法值期望,可以发现dp[i][j] = dp ...
- LOJ2540 [PKUWC2018] 随机算法 【状压DP】
题目分析: 听说这题考场上能被$ O(4^n) $的暴力水过,难不成出题人是毕姥爷? 首先思考一个显而易见的$ O(n^2*2^n) $的暴力DP.一般的DP都是考虑最近的加入了哪个点,然后删除后递归 ...
- Codeforces Round #419 (Div. 2) C. Karen and Game
C. Karen and Game time limit per test 2 seconds memory limit per test 512 megabytes input standard i ...
- A1016. Phone Bills
A long-distance telephone company charges its customers by the following rules: Making a long-distan ...
- 收藏:解决其它程序与IIS共享80端口的四个方法
今天写的程序也占用80端口,而 IIS也占用 80端口,我在我的一张网卡上分配了两个IP地址,但是测试发现:只要IIS启动后,我写的程序就无法使用80端口,到网上搜索了一下,终于找到了解决办法: 使用 ...
- 智能指针unique_ptr
转自:https://www.cnblogs.com/DswCnblog/p/5628195.html 成员函数 (1) get 获得内部对象的指针, 由于已经重载了()方法, 因此和直接使用对象是一 ...
- typescript基础类型(学习笔记非干货)
布尔值 Boolean let isDone:boolean=false; 数字 Number let decLiteral:number=6; let hexLiteral:number=0xf00 ...
- MyEclipse 检出新项目后,如果项目名称签名有个红色感叹号
MyEclipse 检出新项目后,如果项目名称签名有个红色感叹号,那么看 Problems中的错误提示(如果找不到Problems窗口,点 菜单栏的 Window——Reset Perspective ...
- 在子类中调用父类的方法super
1.没有super之前,在子类里面需要父类里面的逻辑,但是我们是通过派生(自己定义了一个init,增加了一条line) class vehichle:#定义一个交通工具的类 Country=" ...