hdu 3307(欧拉函数+好题)
Description has only two Sentences
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1071 Accepted Submission(s): 323
Your task is to calculate the smallest positive integer k that ak mod a0 = 0.
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <math.h>
using namespace std;
typedef long long LL;
LL e[][];
LL phi(LL x)
{
LL ans=x;
for(LL i=; i*i<=x; i++)
if(x%i==)
{
ans=ans/i*(i-);
while(x%i==) x/=i;
}
if(x>)
ans=ans/x*(x-);
return ans;
}
LL gcd(LL a,LL b)
{
return b==?a:gcd(b,a%b);
}
LL pow_mod(LL a,LL n,LL mod)
{
LL ans = ;
while(n)
{
if(n&) ans=ans*a%mod;
a=a*a%mod;
n>>=;
}
return ans;
}
void devide(LL ans,int &id)
{
for(LL i=; i*i<=ans; i++) ///分解质因数
{
if(ans%i==)
{
e[id][]=i;
e[id][]=;
while(ans%i==) ans/=i,e[id][]++;
id++;
}
}
if(ans>)
{
e[id][]=ans;
e[id++][]=;
}
} int main()
{
LL X,Y,a0;
while(~scanf("%lld%lld%lld",&X,&Y,&a0))
{
Y = Y/(X-);
LL d = gcd(Y,a0);
a0 = a0/d;
if(gcd(X,a0)!=)
{
printf("Impossible!\n");
}
else
{
LL ans = phi(a0);
int id = ;
devide(ans,id);
for(int i=; i<id; i++)
{
for(int j=; j<e[i][]; j++)
{
if(pow_mod(X,ans/e[i][],a0)==) ans/=e[i][]; ///分解本身,得到 X^ans % a0 = 1的最小ans
}
}
printf("%lld\n",ans);
}
}
return ;
}
hdu 3307(欧拉函数+好题)的更多相关文章
- 找新朋友 HDU - 1286 欧拉函数模板题
题意: 求出来区间[1,n]内与n互质的数的数量 题解: 典型的欧拉函数应用,具体见这里:Relatives POJ - 2407 欧拉函数 代码: 1 #include<stdio.h> ...
- hdu 1286 找新朋友 欧拉函数模版题
找新朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem Des ...
- (hdu step 7.2.1)The Euler function(欧拉函数模板题——求phi[a]到phi[b]的和)
题目: The Euler function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- UVA 10820 欧拉函数模板题
这道题就是一道简单的欧拉函数模板题,需要注意的是,当(1,1)时只有一个,其他的都有一对.应该对欧拉函数做预处理,显然不会超时. #include<iostream> #include&l ...
- hdu 6390 欧拉函数+容斥(莫比乌斯函数) GuGuFishtion
http://acm.hdu.edu.cn/showproblem.php?pid=6390 题意:求一个式子 题解:看题解,写代码 第一行就看不出来,后面的sigma公式也不会化简.mobius也不 ...
- POJ 2407 Relatives(欧拉函数入门题)
Relatives Given n, a positive integer, how many positive integers less than n are relatively prime t ...
- hdu 2824(欧拉函数)
The Euler function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- poj2407(欧拉函数模板题)
题目链接:https://vjudge.net/problem/POJ-2407 题意:给出n,求0..n-1中与n互质的数的个数. 思路:欧拉函数板子题,先根据唯一分解定理求出n的所有质因数p1,p ...
- HDU 6322.Problem D. Euler Function -欧拉函数水题(假的数论题 ̄▽ ̄) (2018 Multi-University Training Contest 3 1004)
6322.Problem D. Euler Function 题意就是找欧拉函数为合数的第n个数是什么. 欧拉函数从1到50打个表,发现规律,然后勇敢的水一下就过了. 官方题解: 代码: //1004 ...
随机推荐
- pandas删除及其映射修改操作。
1.使用drop_duplicates()函数删除重复的行 df.drop_duplicates() 2.映射 映射的含义,创建一个映射关系,把values元素和一个特定的标签或字符串绑定 map = ...
- 【Python学习之七】递归——汉诺塔问题的算法理解
汉诺塔问题 汉诺塔的移动可以用递归函数非常简单地实现.请编写move(n, a, b, c)函数,它接收参数n,表示3个柱子A.B.C中第1个柱子A的盘子数量,然后打印出把所有盘子从A借助B移动到C的 ...
- Ubuntu 16.04系统安装步骤
1.安装系统 2.设置更新源,自动检测最优更新源 3.关闭自动更新 4.设置终端样式 5.设置终端快捷键 6.安装vim,配置.vimrc 7.修改.bashrc第62行,小写w为大写W,设置终端不显 ...
- python3 连接 mysql和mariadb的模块
是pymysql python2中是MySQL-python sudo pip install pymysql 参考博客https://www.jb51.net/article/140387.htm
- Python学习笔记:re模块(正则表达式)
本文是部分内容参考自:http://www.cnblogs.com/huxi/archive/2010/07/04/1771073.html,虽然这篇博客是基于Python2.4的老版本,但是基础的P ...
- 大小端测试C实现
int is_little_endian(void)//判断是否是小端的函数 { union check_fun { int a; char b; }u1; u1.a=;//先将1(实际上就是0x00 ...
- zookeeper安装、配置、使用
[安装] wget http://www.apache.org/dist/zookeeper/zookeeper-3.3.6/zookeeper-3.3.6.tar.gz tar zxvf zooke ...
- cygwin的使用
参考资料: 对话 UNIX: 在 Windows 上使用 Cygwin Cygwin使用指南
- 在ionic项目中使用极光推送实现推送 & 服务器端代码
ionic start -a jPushDemo -i com.lawxin.fengkong jpushdemo blank meteor add cordova:cn.jpush.phonegap ...
- BZOJ 5441: [Ceoi2018]Cloud computing
背包 #include<cstdio> #include<algorithm> using namespace std; int n,m,Len; long long F[2] ...