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 ...
随机推荐
- numpy中常用的函数
1. power(x1, x2) 对x1中的每个元素求n次方.不会改变x1上午shape. 2. sum(a, axis=None, dtype=None, out=None, keepdims=Fa ...
- Linux 命令、配置文件及操作
Linux 命令.配置文件及操作 命令 命令 参数 说明 A alias.unalias 命令别名 B C cat 查看文件内容 cd 切换目录 chown 修改拥有着 chgrp 修改所属组 chm ...
- Unity基础-脚本的基本使用
脚本的基本使用 定义与挂载monobehaviour 1.新建一个场景 2.新建脚本 using System.Collections; using System.Collections.Generi ...
- css制作三角形,下拉框三角形
网站制作中常常需要下拉框,而如果下拉框如果只是单纯的矩形则会显得太过单调,所以这次教大家利用css制作三角形放在矩形上面 首先利用css制作三角形 div { width:0px; height:0p ...
- 水题:51Nod1432-独木舟
1432 独木舟 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 Problem Description n个人,已知每个人体重.独木舟承重固定,每只独木舟最多坐两 ...
- Linux学习-YUM 在线升级机制
这个 yum 是透过分析 RPM 的标头资料后, 根据 各软件的相关性制作出属性相依时的解决方案,然后可以自动处理软件的相依属性问题,以解决软件 安装或移除与升级的问题. 利用 yum 进行查询.安装 ...
- 利用Windbg深入理解变量的存储模型
下面的是一个简单的测试程序,基本包括了所有的变量类型,包括静态的,常量的,全局的,本地的,还有new出来的 #include <iostream> using namespace std; ...
- BZOJ 4355: Play with sequence
调了好久,还是黑盒测试有前途 我以前怕不是学了假的吉利线段树(我第一次知道还要记次小值去更新的........) #include<cstdio> #include<algorith ...
- joyoi tyvj1313 [NOIP2010初赛]烽火传递
单调队列优化dp #include <iostream> #include <cstdio> using namespace std; int dp[1000005], n, ...
- luogu1242 新汉诺塔
就是一步一步把大的往目标地放. #include <iostream> #include <cstdio> using namespace std; int fro[55], ...