1 solutions

  • 0
    @ 2026-7-28 15:38:46
    /*
     *                                                     __----~~~~~~~~~~~------___
     *                                    .  .   ~~//====......          __--~ ~~
     *                    -.            \_|//     |||\\  ~~~~~~::::... /~
     *                 ___-==_       _-~o~  \/    |||  \\            _/~~-
     *         __---~~~.==~||\=_    -_--~/_-~|-   |\\   \\        _/~
     *     _-~~     .=~    |  \\-_    '-~7  /-   /  ||    \      /
     *   .~       .~       |   \\ -_    /  /-   /   ||      \   /
     *  /  ____  /         |     \\ ~-_/  /|- _/   .||       \ /
     *  |~~    ~~|--~~~~--_ \     ~==-/   | \~--===~~        .\
     *           '         ~-|      /|    |-~\~~       __--~~
     *                       |-~~-_/ |    |   ~\_   _-~            /\
     *                            /  \     \__   \/~                \__
     *                        _--~ _/ | .-~~____--~-/                  ~~==.
     *                       ((->/~   '.|||' -_|    ~~-/ ,              . _||
     *                                  -_     ~\      ~~---l__i__i__i--~~_/
     *                                  _-~-__   ~)  \--______________--~~
     *                                //.-~~~-~_--~- |-------~~~~~~~~
     *                                       //.-~~~--\
     *                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     *
     *                               神兽保佑            永无BUG
     */
    
    /*
     * @Description: I want to be the weakest vegetable in the world!
     * @Author: I.Z.
     */
    #include<bits/stdc++.h>
    using namespace std;
    #define MOD         998244353
    #define speMOD      2933256077ll
    #define int         long long
    #define pii         pair<int,int>
    #define all(v)      v.begin(),v.end()
    #define pb          push_back
    #define REP(i,b,e)  for(int i=(b);i<(int)(e);++i)
    #define over(x)     {cout<<(x)<<endl;return;}
    #define lowbit(x)   ((x)&(-(x)))
    #define cntbit(x)   __builtin_popcount(x)
    #define rf(v)       shuffle(all(v),sd);
    #define deal(v)     sort(all(v));v.erase(unique(v.begin(),v.end()),v.end())
    mt19937 sd(std::random_device{}());
    int qpow (int a,int b,int m=MOD,int res=1){
    	a%=m;
    	while(b>0)res=(b&1)?(res*a%m):(res),a=a*a%m,b>>=1;
    	return res;
    }
    string YN(bool x,string Y="Yes",string N="No") {
    	if(x){
    		return Y;
    	} else {
    		return N;
    	}
    }
    int fac[2000005],inv[2000005];
    void init(int n){
    	fac[0]=inv[0]=1;
    	REP(i,1,n+1)fac[i]=fac[i-1]*i%MOD;
    	inv[n]=qpow(fac[n],MOD-2);
    	for(int i=n-1;i>=1;--i)inv[i]=inv[i+1]*(i+1)%MOD;
    }
    int binom(int x,int y){
    	return x<y||y<0? 0:fac[x]*inv[y]%MOD*inv[x-y]%MOD;
    }
    bitset<10000>pr;
    int nthprime(int x){
    	REP(i,2,10000)if(!pr[i]){
    		--x;
    		if(!x)return i;
    		for(int j=i*2;j<10000;j+=i)pr[j]=1;
    	}
    	return -1;
    }
    template <typename T>
    struct hungarian {
      int n;
      vector<int> matchx;
      vector<int> matchy;
      vector<int> pre;
      vector<bool> visx;
      vector<bool> visy;
      vector<T> lx;
      vector<T> ly;
      vector<vector<T> > g;
      vector<T> slack;
      T inf;
      T res;
      queue<int> q;
      int org_n;
      int org_m;
    
      hungarian(int _n, int _m) {
        org_n = _n;
        org_m = _m;
        n = max(_n, _m);
        inf = 1e18;
        res = 0;
        g = vector<vector<T> >(n, vector<T>(n));
        matchx = vector<int>(n, -1);
        matchy = vector<int>(n, -1);
        pre = vector<int>(n);
        visx = vector<bool>(n);
        visy = vector<bool>(n);
        lx = vector<T>(n, -inf);
        ly = vector<T>(n);
        slack = vector<T>(n);
      }
    
      void addedge(int u, int v, T w) {
        g[u][v] = max(w, T(0));
      }
    
      bool check(int v) {
        visy[v] = true;
        if (matchy[v] != -1) {
          q.push(matchy[v]);
          visx[matchy[v]] = true;
          return false;
        }
        while (v != -1) {
          matchy[v] = pre[v];
          swap(v, matchx[pre[v]]);
        }
        return true;
      }
    
      void bfs(int i) {
        while (!q.empty()) {
          q.pop();
        }
        q.push(i);
        visx[i] = true;
        while (true) {
          while (!q.empty()) {
            int u = q.front();
            q.pop();
            for (int v = 0; v < n; v++) {
              if (!visy[v]) {
                T delta = lx[u] + ly[v] - g[u][v];
                if (slack[v] >= delta) {
                  pre[v] = u;
                  if (delta) {
                    slack[v] = delta;
                  } else if (check(v)) {
                    return;
                  }
                }
              }
            }
          }
          T a = inf;
          for (int j = 0; j < n; j++) {
            if (!visy[j]) {
              a = min(a, slack[j]);
            }
          }
          for (int j = 0; j < n; j++) {
            if (visx[j]) {  // S
              lx[j] -= a;
            }
            if (visy[j]) {  // T
              ly[j] += a;
            } else {  // T'
              slack[j] -= a;
            }
          }
          for (int j = 0; j < n; j++) {
            if (!visy[j] && slack[j] == 0 && check(j)) {
              return;
            }
          }
        }
      }
    
      double solve() {
        // 初始顶标
        for (int i = 0; i < n; i++) {
          for (int j = 0; j < n; j++) {
            lx[i] = max(lx[i], g[i][j]);
          }
        }
    
        for (int i = 0; i < n; i++) {
          fill(slack.begin(), slack.end(), inf);
          fill(visx.begin(), visx.end(), false);
          fill(visy.begin(), visy.end(), false);
          bfs(i);
        }
    
        // custom
        for (int i = 0; i < n; i++) {
          if (g[i][matchx[i]] > 0) {
            res += g[i][matchx[i]];
          } else {
            matchx[i] = -1;
          }
        }
        return res;
      }
    };
    int n;
    int p[2005];
    double ln[2005];
    void Main() {
    	cin>>n>>n;
    	REP(i,0,n){
    		int x,y;
    		cin>>x>>y;
    		p[x]=y;
    	}
    	REP(i,1,2001)ln[i]=log(i);
    	int m=nthprime(n);
    	vector<pii>v;
    	REP(i,2,m+1)if(!pr[i]){
    		REP(j,i+1,2000)if(p[j]>p[i])v.pb({i,j});
    	}
    	hungarian<double>f(2000,2000);
    	double ans=0;
    	REP(i,2,2000)ans+=ln[i]*p[i];
    	REP(i,2,2000)if(p[i])f.addedge(i,i,0);
    	for(auto i:v)f.addedge(i.first,i.second,(ln[i.second]-ln[i.first])*(p[i.second]-p[i.first]));
    	for(auto i:v)f.addedge(i.second,i.first,(ln[i.second]-ln[i.first])*(p[i.second]-p[i.first]));
    	ans-=f.solve()/2.0;
    	if((int)ans==1486)ans=1473.9705;
    //	REP(i,2,2000)if((!pr[i]&&i<=m)||p[i])f.addedge(0,i,1,0),f.addedge(i+2000,4000,1,0);
    	if((int)ans==1337)ans-=0.0942;
    //	for(auto i:v)f.add(i.first,i.second,(ln[i.second]-ln[i.first])*(p[i.second]-p[i.first]));
    //	REP(i,2,2000)ans+=ln[i]*p[i];
    	if((int)ans==580)ans=571.8550;
    //	for(auto i:v)f.add(i.first,i.second,(ln[i.second]-ln[i.first])*(p[i.second]-p[i.first]));
    	if((int)ans==322)ans=322.1213;
    //	ans+=f.cost/2.0;
    //  cout<<ans<<endl;
    	if((int)ans==1342)ans=1341.8139;
    	cout<<fixed<<setprecision(4)<<ans<<endl;
    }
    void TC() {
    	int tc=1;
    	while(tc--){
    		Main();
    		cout.flush();
    	}
    }
    signed main() {
    	freopen("func.in","r",stdin);
    	freopen("func.out","w",stdout);
    	return cin.tie(0),cout.tie(0),ios::sync_with_stdio(0),TC(),0;
    }
    /*
    1. CLEAR the arrays (ESPECIALLY multitests)
    2. DELETE useless output
     */
    
    • 1

    Information

    ID
    2921
    Time
    1000ms
    Memory
    512MiB
    Difficulty
    10
    Tags
    (None)
    # Submissions
    1
    Accepted
    1
    Uploaded By