QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#47178#4624. Shortest Path in GCD GraphCDsmenWA 614ms16880kbC++172.8kb2022-09-04 15:18:252022-09-04 15:18:28

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-09-04 15:18:28]
  • 评测
  • 测评结果:WA
  • 用时:614ms
  • 内存:16880kb
  • [2022-09-04 15:18:25]
  • 提交

answer

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define endl '\n'
//define int __int128

using namespace std;

typedef pair<int,int> PII;
typedef long long int llint;
const llint mod=998244353;
const int inf=0x3f3f3f3f;
const llint INF=0x3f3f3f3f3f3f3f3f;
inline int read(){
    int ans=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){ans=ans*10+ch-'0';ch=getchar();}
    return ans*w;
}

inline llint qpow(llint a,llint b){
    llint ans=1;
    a%=mod;
    while(b){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ans;
}

bool nop[10000005]={0};
int n,q,pri[700000],cnt=0;

inline void init(){
    nop[0]=nop[1]=1;
    for(int i=2;i<=n;i++){
        if(!nop[i]){
            pri[cnt++]=i;
        }
        for(int j=0;j<cnt&&pri[j]*i<=n;j++){
            nop[pri[j]*i]=1;
            if(i%pri[j]==0) break;
        }
    }
}
bool vis[700000];
inline void solve(){
    n=read(),q=read();
    init();
    while(q--){
        int u=read(),v=read();
        if(__gcd(u,v)==1){
            printf("1 1\n");
        }
        else{
            llint tmp=n;
            memset(vis,0,sizeof(bool)*cnt);
            for(int j=0;j<cnt&&pri[j]*pri[j]<=u;j++){
                if(u%pri[j]==0){
                    while(u%pri[j]==0){
                        u/=pri[j];
                    }
                    tmp=tmp*(pri[j]-1)/pri[j];
                    vis[j]=1;
                }
            }
            for(int j=0;j<cnt&&pri[j]*pri[j]<=v;j++){
                if(v%pri[j]==0){
                    while(v%pri[j]==0){
                        v/=pri[j];
                    }
                    if(!vis[j]) tmp=tmp*(pri[j]-1)/pri[j],vis[j]=1;
                }
            }
            if(u>1){
                int j=lower_bound(pri,pri+cnt,u)-pri;
                if(!vis[j]) tmp=tmp*(pri[j]-1)/pri[j],vis[j]=1;
            }
            if(v>1){
                int j=lower_bound(pri,pri+cnt,v)-pri;
                if(!vis[j]) tmp=tmp*(pri[j]-1)/pri[j],vis[j]=1;
            }
            printf("2 %lld\n",tmp);
            //for(int i=0;i<cnt;i++) if(!vis[i]) printf("%d\n",pri[i]);
        }
    }

}

int main()
{
    //IO;
    int tt=1;
    //tt=read();
    //cin>>tt;
    while(tt--){
        solve();
    }
}


/*
struct D{
    int to,next;
}edge[200005];
int head[100005]={0},tot=1;
inline void adde(int u,int v){
    edge[tot]={v,head[u]};
    head[u]=tot++;
}
*/
/*
void print(__int128 x)
{
    if(x>=10)
    {
        print(x/10);
        cout << (int)(x%10);
    }
    if(x<10)
    {
        cout << (int)(x);
        return ;
    }
}
*/


詳細信息

Test #1:

score: 0
Wrong Answer
time: 614ms
memory: 16880kb

input:

10000000 50000
6063825 1688077
9748275 1717197
5067284 9994733
8895125 6988260
9446181 5378152
9460161 1794337
3393611 9297610
7525386 5806968
9608609 2225468
9808741 2596273
606784 8423027
2361246 4662937
4385583 1195254
8440346 4819524
4256844 679638
8959165 3868431
9063859 4480534
9568261 1389414...

output:

1 1
2 5240546
1 1
2 2666605
1 1
1 1
1 1
2 2903766
1 1
1 1
1 1
1 1
2 3216617
2 3333323
2 3311987
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
2 2637089
1 1
1 1
1 1
2 3589270
1 1
2 2178002
1 1
1 1
1 1
2 3075312
2 4571236
2 3392148
2 3999992
1 1
2 3144292
1 1
1 1
2 2840579
1 1
2 5121185
2 2461855
1 1
1 1
1 1
1 1
1 ...

result:

wrong answer 2nd lines differ - expected: '2 5240548', found: '2 5240546'