Test instructions: Number of K and M coprime.
The principle of tolerance to find the number of [1,l] and M coprime, and then two K can be.
#define_crt_secure_no_warnings#include<stdio.h>#include<iostream>#include<string>#include<queue>#include<stack>#include<list>#include<stdlib.h>#include<algorithm>#include<vector>#include<map>#include<cstring>#include<Set>using namespaceStd;typedefLong LongLL;ConstLL INF = (1LL) << +; Vector<LL>Q; LL ans;voidAsk (ll X, ll pre, LL flag, ll key) {if(x = =q.size ()) { if(Flag = =0) ans-= key/Pre; ElseAns + = key/Pre; return; } Ask (x+1, Pre, flag, key); Ask (x+1, Pre*q[x], flag ^1, key);} ll Erfen (ll L, LL R, ll key) {ll-cnt= -1; while(L <=r) {LL mid= (L + r) >>1; Ans=0; Ask (0,1,1, mid); if(ans = =key) {CNT=mid; } if(Key <= ans) R = mid-1; ElseL = mid +1; } returnCNT;}intMain () {LL m, K; while(SCANF ("%i64d%i64d", &m, &k)! =EOF) {q.clear (); LL T=m; for(LL i =2; I*i <= t; i++) { if(t%i)Continue; while(t%i==0) T/=i; Q.push_back (i); } if(T >1) Q.push_back (t); LL cc= Erfen (1, INF, K); cout<< cc <<Endl; } return 0;}
Poj2773 principle of tolerance and repulsion