zoukankan      html  css  js  c++  java
  • 【Codeforces 1009D】Relatively Prime Graph

    【链接】 我是链接,点我呀:)
    【题意】

    题意

    【题解】

    1000以内就有非常多组互质的数了(超过1e5) 所以,直接暴力就行...很快就找完了 (另外一开始头n-1条边找1和2,3...n就好

    【代码】

    #include <bits/stdc++.h>
    #define ll long long
    using namespace std;
    
    int n,m;
    vector<pair<int,int> > v;
    
    int main(){
        ios::sync_with_stdio(0),cin.tie(0);
        cin >> n >> m;
        if (m<n-1){
            cout<<"Impossible"<<endl;
        }else {
            for (int i = 1;i <= n && m>0;i++)
                for (int j = i+1;j <= n && m > 0;j++){
                    if (__gcd(i,j)==1){
                        v.push_back(make_pair(i,j));
                        m--;
                    }
                }
            if (m>0){
                cout<<"Impossible"<<endl;
            }else{
                cout<<"Possible"<<endl;
                for (pair<int,int> temp:v){
                    cout<<temp.first<<" "<<temp.second<<endl;
                }
            }
        }
    	return 0;
    }
    
    
  • 相关阅读:
    curl continue
    actor
    nginx
    jmx additional port
    diff
    lsof
    zk reconnect
    Python:Python基础(一)
    Python:初识Python(二)
    Python:初识Python(一)
  • 原文地址:https://www.cnblogs.com/AWCXV/p/10649376.html
Copyright © 2011-2022 走看看