关注
注意到N只有1000 莫比乌斯可快速求得 1-N和1-M gcd为i的个数 枚举就行了 import java.io.*;
import java.util.*;
public class Main {
static int[]prime=new int[100050];
static boolean[]notp=new boolean[100050];
static int[]mu=new int[100050];
public static void main(String[] args) {
FastScanner sc=new FastScanner();
PrintWriter pw=new PrintWriter(System.out);
int N=sc.nextInt();
int n=sc.nextInt();
int m=sc.nextInt();
int p=sc.nextInt();
makeMobius();
int[]A=new int[N+1];
A[1]=p;
for(int i=2;i<=N;i++){
A[i]=(A[i-1]+153)%p;
}
long res=0;
for(int o=1;o<=N;o++){
long min=Math.min(n,m)/o;
long max=Math.max(n,m)/o;
long count1=0;
long count2=0;
for(int i=1;i<=min;i++){
count2+=mu[i]*(min/i)*(max/i);
}
res+=A[o]*count2;
}
pw.println(res);
pw.flush();
}
static int gcd(int a,int b){
return a==0?b:gcd(b%a,a);
}
static void makeMobius() {
Arrays.fill(notp, false);
mu[1] = 1;
int pnum=0;
for (int i = 2; i < 100010; i++) {
if (!notp[i]) {
prime[++pnum] = i; mu[i] = -1;
}
for (int j = 1; prime[j]*i < 100010; j++) {
notp[prime[j]*i] = true;
if (i%prime[j] == 0) {
mu[prime[j]*i] = 0;
break;
}
mu[prime[j]*i] = -mu[i];
}
}
}
}
class FastScanner{
BufferedReader br;
StringTokenizer st;
FastScanner(){
br=new BufferedReader(new InputStreamReader(System.in));
st=new StringTokenizer("");
}
String nextLine(){
String s="";
try {
s=br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return s;
}
boolean hasNext(){
String s = "";
while(!st.hasMoreTokens()){
s=nextLine();
if(s==null)return false;
st=new StringTokenizer(s);
}
return true;
}
String next(){
String s="";
while(!st.hasMoreTokens()){
s=nextLine();
st=new StringTokenizer(s);
}
return st.nextToken();
}
int nextInt(){
return Integer.valueOf(next());
}
long nextLong(){
return Long.valueOf(next());
}
double nextDouble(){
return Double.valueOf(next());
}
}
查看原帖
点赞 评论
相关推荐
点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 在大厂上班是一种什么样的体验 #
12465次浏览 168人参与
# 你的mentor是什么样的人? #
51181次浏览 723人参与
# 程序员找工作至少要刷多少题? #
21331次浏览 272人参与
# 我和mentor的爱恨情仇 #
106311次浏览 950人参与
# 论秋招对个人心气的改变 #
13554次浏览 191人参与
# 机械人避雷的岗位/公司 #
44189次浏览 309人参与
# 为了减少AI幻觉,你注入过哪些设定? #
6122次浏览 183人参与
# 秋招落幕,你是He or Be #
54246次浏览 618人参与
# 校招第一份工作你干了多久? #
136664次浏览 597人参与
# 高薪高压 vs 低薪wlb,你怎么选? #
47415次浏览 291人参与
# 设计人如何选offer #
189728次浏览 868人参与
# 考公VS就业,你怎么选? #
91995次浏览 507人参与
# 职场上哪些行为很加分? #
322607次浏览 3603人参与
# 你的秋招进行到哪一步了 #
2531038次浏览 23253人参与
# 牛客AI体验站 #
7808次浏览 210人参与
# 机械人还在等华为开奖吗? #
312135次浏览 1582人参与
# 秋招投递记录 #
380945次浏览 3204人参与
# 12306一秒售罄,你抢到回家的票了吗? #
2327次浏览 52人参与
# 我现在比当时_,你想录用我吗 #
9473次浏览 129人参与
# 重来一次,我还会选择这个专业吗 #
411308次浏览 3898人参与