QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#864469#3295. 循环之美q1uple48 252ms55104kbC++144.3kb2025-01-20 17:10:582025-01-20 17:11:08

Judging History

你现在查看的是最新测评结果

  • [2025-01-20 17:11:08]
  • 评测
  • 测评结果:48
  • 用时:252ms
  • 内存:55104kb
  • [2025-01-20 17:10:58]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e6+6,mod=1e9+7,INF=2e9;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
#define qmi(a,b) a=min(a,b)
#define qma(a,b) a=max(a,b)
#define rep(i,l,r) for(int i=(l);i<=(r);i++)
#define atrep(i,l,r) for(int i=(r);i>=(l);i--)
#define vec vector<int>
#define pb push_back
namespace fast_IO {
#define IOSIZE 100000
	char ibuf[IOSIZE], obuf[IOSIZE], *p1 = ibuf, *p2 = ibuf, *p3 = obuf;
#define getchar() ((p1==p2)and(p2=(p1=ibuf)+fread(ibuf,1,IOSIZE,stdin),p1==p2)?(EOF):(*p1++))
#define putchar(x) ((p3==obuf+IOSIZE)&&(fwrite(obuf,p3-obuf,1,stdout),p3=obuf),*p3++=x)
#define isdigit(ch) (ch>47&&ch<58)
#define isspace(ch) (ch<33)
	template<typename T> inline T read() { T s = 0; int w = 1; char ch; while (ch = getchar(), !isdigit(ch) and (ch != EOF)) if (ch == '-') w = -1; if (ch == EOF) return false; while (isdigit(ch)) s = s * 10 + ch - 48, ch = getchar(); return s * w; }
	template<typename T> inline bool read(T &s) { s = 0; int w = 1; char ch; while (ch = getchar(), !isdigit(ch) and (ch != EOF)) if (ch == '-') w = -1; if (ch == EOF) return false; while (isdigit(ch)) s = s * 10 + ch - 48, ch = getchar(); return s *= w, true; }
	template<typename T> inline void print(T x) { if (x < 0) putchar('-'), x = -x; if (x > 9) print(x / 10); putchar(x % 10 + 48); }
	inline bool read(char &s) { while (s = getchar(), isspace(s)); return true; }
	inline bool read(char *s) { char ch; while (ch = getchar(), isspace(ch)); if (ch == EOF) return false; while (!isspace(ch)) *s++ = ch, ch = getchar(); *s = '\000'; return true; }
	inline void print(char x) { putchar(x); }
	inline void print(char *x) { while (*x) putchar(*x++); }
	inline void print(const char *x) { for (int i = 0; x[i]; i++) putchar(x[i]); }
	inline bool read(std::string& s) { s = ""; char ch; while (ch = getchar(), isspace(ch)); if (ch == EOF) return false; while (!isspace(ch)) s += ch, ch = getchar(); return true; }
	inline void print(std::string x) { for (int i = 0, n = x.size(); i < n; i++) putchar(x[i]); }
	inline bool read(bool &b) { char ch; while(ch=getchar(), isspace(ch)); b=ch^48; return true; }
	inline void print(bool b) { putchar(b+48); }
	template<typename T, typename... T1> inline int read(T& a, T1&... other) { return read(a) + read(other...); }
	template<typename T, typename... T1> inline void print(T a, T1... other) { print(a), print(other...); }
	struct Fast_IO { ~Fast_IO() { fwrite(obuf, p3 - obuf, 1, stdout); } } io;
	template<typename T> Fast_IO& operator >> (Fast_IO &io, T &b) { return read(b), io; }
	template<typename T> Fast_IO& operator << (Fast_IO &io, T b) { return print(b), io; }
#define cout io
#define cin io
#define endl '\n'
} using namespace fast_IO;
const int XR=1e6;
int pr[N],tot,mu[N],pk[N],len=0;
bitset<N>vis;
void Euler(int n,int k){
    mu[1]=1;
    rep(i,2,n){
        if(!vis[i]) pr[++tot]=i,mu[i]=-1;
        for(int j=1;j<=tot&&pr[j]*i<=n;j++){
            vis[i*pr[j]]=1;
            if(i%pr[j]==0){
                mu[i*pr[j]]=0;
                break;
            }else{
                mu[i*pr[j]]=-mu[i];
            }
        }
    }
    rep(i,1,n)  mu[i]+=mu[i-1];
    for(int i=1;i<=tot&&pr[i]<=k;i++){
        while(k%(pr[i]*pr[i])==0)   k/=pr[i];
        if(k%pr[i]==0)pk[++len]=pr[i];
    }
}
unordered_map<int,int>mp1;
int solve1(int x){
    if(x<=XR)   return mu[x];
    if(mp1[x])  return mp1[x];
    int res=1;
    for(int l=2,r=0;l<=x;l=r+1){
        r=(x/(x/l));
        res=res-solve1(x/l)*(r-l+1);
    }
    return res=mp1[x];
}
unordered_map<int,unordered_map<int,int> >F,G;
int f(int n,int k,int now){
    if(!n)  return 0;
    if(k==1)    return n;
    if(F[n][k]) return F[n][k];
    return F[n][k]=f(n,k/pk[now],now+1)-f(n/pk[now],k/pk[now],now+1);
}
int g(int n,int k,int now){
    if(!n)  return 0;
    if(k==1)    return solve1(n);
    if(G[n][k]) return G[n][k];
    return G[n][k]=g(n,k/pk[now],now+1)+g(n/pk[now],k,now);
}
signed main(){
    int n,m,k;
    cin>>n>>m>>k;
    Euler(XR,k);
    int res=0;
    for(int l=1,r=0;l<=min(n,m);l=r+1){
        r=min(n/(n/l),m/(m/l));
        res=res+(f(m/l,k,1))*(g(r,k,1)-g(l-1,k,1))*(n/l);
    }
    cout<<res<<endl;
}

詳細信息


Pretests


Final Tests

Test #1:

score: 4
Accepted
time: 6ms
memory: 12588kb

input:

9 19 2

output:

78

result:

ok 1 number(s): "78"

Test #2:

score: 4
Accepted
time: 5ms
memory: 14524kb

input:

97 9998 2

output:

395230

result:

ok 1 number(s): "395230"

Test #3:

score: 4
Accepted
time: 6ms
memory: 15000kb

input:

925 776383828 2

output:

291158369963

result:

ok 1 number(s): "291158369963"

Test #4:

score: 4
Accepted
time: 9ms
memory: 16560kb

input:

8901 326326877 2

output:

1177246855340

result:

ok 1 number(s): "1177246855340"

Test #5:

score: 4
Accepted
time: 4ms
memory: 16692kb

input:

10 18 3

output:

85

result:

ok 1 number(s): "85"

Test #6:

score: 4
Accepted
time: 5ms
memory: 16696kb

input:

99 9124 3

output:

414445

result:

ok 1 number(s): "414445"

Test #7:

score: 4
Accepted
time: 6ms
memory: 14908kb

input:

876 435006787 3

output:

173773888677

result:

ok 1 number(s): "173773888677"

Test #8:

score: 4
Accepted
time: 7ms
memory: 22772kb

input:

9077 999901423 3

output:

4138517057280

result:

ok 1 number(s): "4138517057280"

Test #9:

score: 4
Accepted
time: 6ms
memory: 14532kb

input:

8 18 70

output:

44

result:

ok 1 number(s): "44"

Test #10:

score: 0
Runtime Error

input:

99 7689 100

output:


result:


Test #11:

score: 0
Runtime Error

input:

904 791040170 780

output:


result:


Test #12:

score: 0
Runtime Error

input:

9752 700341570 1900

output:


result:


Test #13:

score: 0
Runtime Error

input:

67890 96085338 98

output:


result:


Test #14:

score: 4
Accepted
time: 78ms
memory: 44368kb

input:

199752 831377991 582

output:

49964059187765

result:

ok 1 number(s): "49964059187765"

Test #15:

score: 4
Accepted
time: 56ms
memory: 31908kb

input:

402829 239198013 1974

output:

25093728301882

result:

ok 1 number(s): "25093728301882"

Test #16:

score: 4
Accepted
time: 29ms
memory: 23692kb

input:

920812 97518123 30

output:

22745569858620

result:

ok 1 number(s): "22745569858620"

Test #17:

score: 0
Runtime Error

input:

2000000 902323111 630

output:


result:


Test #18:

score: 0
Wrong Answer
time: 170ms
memory: 55008kb

input:

5000000 1000000000 1122

output:

1315768281251685

result:

wrong answer 1st numbers differ - expected: '1315768281328847', found: '1315768281251685'

Test #19:

score: 0
Runtime Error

input:

10000000 100000000 100

output:


result:


Test #20:

score: 0
Wrong Answer
time: 252ms
memory: 55104kb

input:

19283746 992837465 330

output:

4445506723633954

result:

wrong answer 1st numbers differ - expected: '4445506723817465', found: '4445506723633954'

Test #21:

score: 0
Runtime Error

input:

20000000 1000000000 1540

output:


result:


Test #22:

score: 0
Wrong Answer
time: 87ms
memory: 27576kb

input:

79331983 76782798 210

output:

1350083306194017

result:

wrong answer 1st numbers differ - expected: '1350083306292618', found: '1350083306194017'

Test #23:

score: 0
Wrong Answer
time: 88ms
memory: 24392kb

input:

99997327 86263723 1999

output:

5241443367977355

result:

wrong answer 1st numbers differ - expected: '5241443368179591', found: '5241443367977355'

Test #24:

score: 0
Runtime Error

input:

967272686 923726686 1260

output:


result:


Test #25:

score: 0
Runtime Error

input:

999193233 997313141 1848

output:


result: