前置技能:

<=i且与i互质的数的和是phi(i)*i/2

思路:

显然每个人的步数是gcd(a[i],m)

把m的所有因数预处理出来

1~m-1中的每个数 只会被gcd(m,i)筛掉一遍

//By SiriusRen
#include <cstdio>
#include <algorithm>
using namespace std;
const int N=;
typedef long long ll;
int cases,n,m,a[N],s[N],tp,I=;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int get_phi(int x){
int t=x;
for(int i=;i*i<=x;i++)if(x%i==){
t-=t/i;
while(x%i==)x/=i;
}if(x>)t-=t/x;
return t;
}
int main(){
for(scanf("%d",&cases);I<=cases;I++){
long long ans=;tp=;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
scanf("%d",&a[i]),a[i]=gcd(a[i],m);
sort(a+,a++n);
n=unique(a+,a++n)-a-;
for(int i=;i*i<=m;i++)if(m%i==){
if(i*i==m)s[++tp]=i;
else{
s[++tp]=i;
if(i!=)s[++tp]=m/i;
}
}
for(int i=;i<=tp;i++)
for(int j=;j<=n;j++)if(s[i]%a[j]==){
ans+=get_phi(m/s[i]);break;
}
printf("Case #%d: %lld\n",I,1ll*ans*m/);
}
}

HDU 5514 欧拉函数应用的更多相关文章

  1. hdu 6390 欧拉函数+容斥(莫比乌斯函数) GuGuFishtion

    http://acm.hdu.edu.cn/showproblem.php?pid=6390 题意:求一个式子 题解:看题解,写代码 第一行就看不出来,后面的sigma公式也不会化简.mobius也不 ...

  2. HDU 5514.Frogs-欧拉函数 or 容斥原理

    Frogs Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  3. hdu 2654(欧拉函数)

    Become A Hero Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  4. hdu 2824(欧拉函数)

    The Euler function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  5. hdu 1395(欧拉函数)

    2^x mod n = 1 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  6. hdu 3307(欧拉函数+好题)

    Description has only two Sentences Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/327 ...

  7. 找新朋友 HDU - 1286 欧拉函数模板题

    题意: 求出来区间[1,n]内与n互质的数的数量 题解: 典型的欧拉函数应用,具体见这里:Relatives POJ - 2407 欧拉函数 代码: 1 #include<stdio.h> ...

  8. hdu 2824 欧拉函数 O(nlogn) 和O(n)

    裸题 O(nlogn): #include <cstdio> #include <iostream> #include <algorithm> using name ...

  9. hdu 4983 欧拉函数

    http://acm.hdu.edu.cn/showproblem.php?pid=4983 求有多少对元组满足题目中的公式. 对于K=1的情况,等价于gcd(A, N) * gcd(B, N) = ...

随机推荐

  1. 593. Valid Square

    Problem statement: Given the coordinates of four points in 2D space, return whether the four points ...

  2. codevs3285 转圈游戏

    题目描述 Description n 个小伙伴(编号从 0 到 n-1)围坐一圈玩游戏.按照顺时针方向给 n 个位置编号,从0 到 n-1.最初,第 0 号小伙伴在第 0 号位置,第 1 号小伙伴在第 ...

  3. AHCI IDE

    AHCI模式性能好 IDE模式,提高约20%,使用Windows 7 系统,AHCI 模式是最佳选择,特别是对SSD硬盘IDE是为XP的兼容性,RAID 模式是要有两块以上硬盘才能实现AHCI模式装的 ...

  4. eclipse中j2ee(struts2)部署及相关问题释疑

    1.eclipse中进行web项目开发时.部署的时候和利用myeclipse部署时有非常大不同,由于在myeclipse的工具栏中有一个部署button.而且在myeclipse的preference ...

  5. Datagridview CurrentRow.Index

    int index = dataGridView1.CurrentRow.Index;  //获取当前选择行引导 string str = dataGridView1.Rows[index].Cell ...

  6. EXISTS 执行顺序 CLR-2-2-引用类型和值类型

    EXISTS 执行顺序   select * from a where a.s_status=1 and exists (select orderid from b on a.orderid=b.or ...

  7. 硬件十万个为什么——运放篇(五)PCB设计技巧

    1.在PCB设计时,芯片电源处旁路滤波等电容应尽可能的接近器件.典型距离是小于3MM 2.运算放大器芯片电源处的小陶瓷旁路电容在放大器处于输入高频信号时能够为放大器的高频特性提供能量电容值的选择依据输 ...

  8. 通过java类文件识别JDK编译版本号

    类文件里第5,6.7,8四个字节是jDK版本信息.当中5,6为小版本:7,8为大版本. 大版本号号相应JDK版本号例如以下: JDK版本 7,8字节 JDK8 52(0x34) JDK7 51(0x3 ...

  9. Android解析程序包时出现问题

    Android用户下载我们wcc应用时,偶尔会出现“解析程序包出现问题”的的现象,以下是逐步排查的相关经验: 1. 首先确保这个包本身没有问题. 检测方法:其他手机采用同样的下载方式再下载一次. 解决 ...

  10. java web中的session属性范围和request属性范围

    首先必需要了解client跳转和server端跳转的差别: client跳转: response.sendRedict(String path).地址栏发生改变. 不能传递request属性. ser ...