【HDOJ6641】TDL(数论)

题意:定义f(n,m)是第m小的数字x,使得x>n且gcd(x,n)=1

已知

 

求最小的n使得

 

k<=1e18,m<=1e2

 思路:

 

 

 

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 typedef unsigned int uint;
 5 typedef unsigned long long ull;
 6 typedef pair<int,int> PII;
 7 typedef pair<ll,ll> Pll;
 8 typedef vector<int> VI;
 9 typedef vector<PII> VII;
10 #define N  110000
11 #define M  4100000
12 #define fi first
13 #define se second
14 #define MP make_pair
15 #define pi acos(-1)
16 #define mem(a,b) memset(a,b,sizeof(a))
17 #define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++)
18 #define per(i,a,b) for(int i=(int)a;i>=(int)b;i--)
19 #define lowbit(x) x&(-x)
20 #define Rand (rand()*(1<<16)+rand())
21 #define id(x) ((x)<=B?(x):m-n/(x)+1)
22 #define ls p<<1
23 #define rs p<<1|1
24 
25 const ll MOD=998244353,inv2=(MOD+1)/2;
26       double eps=1e-6;
27       int INF=1e9;
28 
29 
30 int read()
31 {
32    int v=0,f=1;
33    char c=getchar();
34    while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
35    while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
36    return v*f;
37 }
38 
39 ll gcd(ll x,ll y)
40 {
41     if(y==0) return x;
42     return gcd(y,x%y);
43 }
44 
45 ll f(ll n,int m)
46 {
47     //printf("n=%I64d m=%d\n",n,m);
48     ll t=n;
49     while(m)
50     {
51         t++;
52         if(gcd(n,t)==1) m--;
53     }
54     //printf("t=%I64d\n",t);
55     return t;
56 }
57 
58 int main()
59 {
60     //freopen("1.in","r",stdin);
61     int cas=read();
62     while(cas--)
63     {
64         ll k;
65         int m;
66         scanf("%I64d%d",&k,&m);
67         //printf("m=%d\n",m);
68         ll ans=1e18;
69         for(ll t=1;t<=1000;t++)
70         {
71             ll n=k^t;
72             if(n==0) continue;
73             //printf("t=%I64d n=%I64d\n",t,n);
74             if(f(n,m)-n==t) ans=min(ans,n);
75 
76         }
77         if(ans==1e18) printf("-1\n");
78          else printf("%I64d\n",ans);
79     }
80 
81     return 0;
82 }

 

posted on 2019-10-10 20:36  myx12345  阅读(301)  评论(0编辑  收藏  举报

导航