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.怎么让它们统 ...
随机推荐
- LAMP平台部署
LAMP平台的概述 LAMP环境脚本部署:https://github.com/spdir/ShellScripts/tree/master/lamp LAMP的介绍:百度百科 LAMP平台的构成组件 ...
- jenkins--svn基本使用
新建项目 源码管理 #选择svn配置 svn基本信息配置 其中包括: Repository URL: svn://10.101.0.XXX:9507/XXXX Credentials: 配置你的 ...
- UVALive5876-Writings on the Wall-KMP
有两段字符串,第一段的尾和第二段的头可能重合.问有多少种组合的可能. 需要理解一下next数组的意义. #include <cstdio> #include <cstring> ...
- day30 小面试题 去重 (考核 __eq__ 以及 __hash__ )
# 小面试题,要求将一个类的多个对象进行去重 # 使用set方法去重,但是无法实现,因为set 需要依赖eq以及hash, # hash 哈希的是内存地址, 必然不一样 # eq 比较的也是内存地址, ...
- MT【21】任意基底下的距离公式
解析: 评:$\theta=90^0$时就是正交基底下(即直角坐标系下)的距离公式.
- Leetcode 217.存在重复元素 By Python
给定一个整数数组,判断是否存在重复元素. 如果任何值在数组中出现至少两次,函数返回 true.如果数组中每个元素都不相同,则返回 false. 示例 1: 输入: [1,2,3,1] 输出: true ...
- Haproxy Mysql cluster 高可用Mysql集群
-----client-----------haproxy---------mysql1----------mysql2------192.168.1.250 192.168.1.1 192.168. ...
- django xadmin
1.11.13版本下的[安装]: 1.下载分支版本 https://github.com/nocmt/Xadmin1.11.x/archive/master.zip 2.解压,并将其放在site-pa ...
- 【洛谷P3600】 随机数生成器
https://www.luogu.org/problem/show?pid=3600#sub (题目链接) 题意 一个$n$个数的序列,里面每个数值域为$[1,X]$.给$q$个区间,每个区间的权值 ...
- SDL源码阅读笔记(2) video dirver的初始化及选择
write by 九天雁翎(JTianLing) -- blog.csdn.net/vagrxie 前一篇文章 讲了SDL的除video以外的大部分模块.本文主要关注SDL的video模块部分. SD ...