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 ...
随机推荐
- How to setup multimedia on CentOS 7
You will need to also install the EPEL repository as nux-dextop depends on this for some of its pack ...
- TypeError: cannot use a string pattern on a bytes-like object
一劳永逸解决:TypeError: cannot use a string pattern on a bytes-like object TypeError: cannot use a string ...
- An entity cannot be annotated with both @Entity and @MappedSuperclass: com.example1.demo1.Entity.User错误
项目问SpringDataJpa项目,在运行的过程中出现的以下错误: Caused by: org.hibernate.AnnotationException: An entity cannot be ...
- debug环境下打印
#ifdef DEBUG # define NSLog(...) NSLog(__VA_ARGS__) #else # define NSLog(...) {} #endif
- iOS开发-NSLog不打印设置 Prefix
首先在-Prefix.pch,文件里添加如下代码 #ifdef DEBUG #define NSLog(...) NSLog(__VA_ARGS__) #define debugMethod() NS ...
- Could not load file or assembly 'AjaxControlToolkit' or one of its dependencies
Could not load file or assembly 'AjaxControlToolkit' or one of its dependencies. API 调用退出异常. (Except ...
- ubuntu linux下各种格式软件包的安装卸载
http://www.cnblogs.com/mo-beifeng/archive/2011/08/14/2137954.html
- day04_07 while循环01
while循环结构: #while 条件: print("any") print("any") 死循环案例 num = 1 while num<=10 : ...
- LR采用的Sigmoid函数与最大熵(ME) 的关系
LR采用的Sigmoid函数与最大熵(ME) 的关系 从ME到LR 先直接给出最大熵模型的一般形式,后面再给出具体的推导过程. \[\begin{align*} P_w(y|x) &= \df ...
- 聊聊、Nginx GDB与MAIN参数
接着上一篇,我们学习 Nginx 的 main 方法.用 gdb 工具调试 Nginx,首先 gdb nginx.如下: gdb 调试工具有很多的命令,上一篇为了找 main 方法用了 b 命令,也就 ...