Topic Link: point here ....
Meaning
Give you two integers m (1<=m<=1e6), K (1<=k<=1e8). What is the number of K and M coprime?
Exercises
Direct two points + allow to scold.
Code:
#include <cstdio> #include <cstring> #include <iostream> #include <sstream> #include < algorithm> #include <vector> #include <bitset> #include <set> #include <queue> #include < stack> #include <map> #include <cstdlib> #include <cmath> #define PI 2*asin (1.0) #define LL Long Long Define PB push_back #define PA pair<int,int> #define CLR (a,b) memset (A,b,sizeof (a)) #define Lson Lr<<1,l,mid # Define Rson lr<<1|1,mid+1,r #define BUG (x) printf ("%d++++++++++++++++++++%d\n", x,x) #define Key_value Ch[ch[root
][1]][0]c:\program Files\git\bin const LL MOD = 1e9+7;
Const LL N = 1e3+15;
const int MAXN = 5E5+15;
const int letter = 130;
Const LL INF = 1e18;
Const double Pi=acos (-1.0);
const double EPS=1E-10;
using namespace Std;
inline int read () {int X=0,f=1;char ch=getchar (); while (ch< ' 0 ' | |
Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();}
while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} RetuRN X*f;
int x,k;
int vis[n],prime[n],cnt=0;
int ps[30],num;
void Init () {vis[1]=1;
for (int i=2;i<n;i++) {if (!vis[i]) prime[++cnt]=i;
for (int j=1;j<=cnt&&i*prime[j]<n;j++) {vis[i*prime[j]]=1;
if (i%prime[j]==0) break;
}} ll check (ll x) {///[1,x] ll sum=x,ans=1,res=0;
int cc=0;
for (int i=1;i< (1<<num); i++) {cc=0;
LL Ans=1;
for (int j=0;j<num;j++) {if (i& (1<<j)) {cc++;
ANS*=1LL*PS[J];
} if (cc%2) Res+=x/ans;
else Res-=x/ans;
return sum-res;
int main () {init ();
while (scanf ("%d%d", &x,&k)!=eof) {num=0;
for (int i=1;i<=cnt;i++) {if (x%prime[i]==0) {while (x%prime[i]==0) x/=prime[i];
Ps[num++]=prime[i];
} if (x!=1) ps[num++]=x;
LL L=1,r=inf,mid;LL Flag;
while (L<r) {mid= (l+r)/2;
Flag=check (mid);
if (flag<k) l=mid+1;
else R=mid;
printf ("%i64d\n", R);
return 0;
}/* 12 4 * *