日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

TDL(HDU-6641)

發(fā)布時間:2025/3/17 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 TDL(HDU-6641) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Problem Description

For a positive integer?n, let's denote function?f(n,m)?as the?m-th smallest integer?x?that?x>n?and?gcd(x,n)=1. For example,?f(5,1)=6?and?f(5,5)=11.

You are given the value of?m?and?(f(n,m)?n)⊕n, where ``⊕'' denotes the bitwise XOR operation. Please write a program to find the smallest positive integer?nthat?(f(n,m)?n)⊕n=k, or determine it is impossible.

Input

The first line of the input contains an integer T(1≤T≤10), denoting the number of test cases.

In each test case, there are two integers k,m(1≤k≤1018,1≤m≤100).

Output

For each test case, print a single line containing an integer, denoting the smallest n. If there is no solution, output ``-1'' instead.

Sample Input

2
3 5
6 100

Sample Output

5
-1

題意:t 組數據,函數 f(n,m) 表示比 n 大的第 m 小的與 m 互質的數,現在每組給出 k、m 兩個數,對于式子 (f(n,m)-n)n=k,求最小的 n,如果沒有答案,輸出 -1

思路:

對于 (f(n,m)-n)n=k

設 d=f(n,m)-n

那么根據異或的性質,有:d=nk

故而:n=dk

根據質數分布密度定理:素數的分布越來越稀疏,當 1E18 內的任意兩個素數的差不會很大(不會超過 300),因此可以直接枚舉 d 的值來尋找答案

Source Program

#include<iostream> #include<cstdio> #include<cstdlib> #include<string> #include<cstring> #include<cmath> #include<ctime> #include<algorithm> #include<utility> #include<stack> #include<queue> #include<vector> #include<set> #include<map> #include<unordered_map> #include<bitset> #define PI acos(-1.0) #define INF 0x3f3f3f3f #define LL long long #define Pair pair<int,int> LL quickPow(LL a,LL b){ LL res=1; while(b){if(b&1)res*=a; a*=a; b>>=1;} return res; } LL multMod(LL a,LL b,LL mod){ a%=mod; b%=mod; LL res=0; while(b){if(b&1)res=(res+a)%mod; a=(a<<=1)%mod; b>>=1; } return res%mod;} LL quickPowMod(LL a, LL b,LL mod){ LL res=1,k=a; while(b){if((b&1))res=multMod(res,k,mod)%mod; k=multMod(k,k,mod)%mod; b>>=1;} return res%mod;} LL getInv(LL a,LL mod){ return quickPowMod(a,mod-2,mod); } LL GCD(LL x,LL y){ return !y?x:GCD(y,x%y); } LL LCM(LL x,LL y){ return x/GCD(x,y)*y; } const double EPS = 1E-10; const int MOD = 998244353; const int N = 1000+5; const int dx[] = {-1,1,0,0,1,-1,1,1}; const int dy[] = {0,0,-1,1,-1,1,-1,1}; using namespace std;LL cal(LL n, int m) {if (n < 1) return 0;else{LL i=n+1;while(true){if (GCD(n, i) == 1) {m--;if (!m)return i - n;}i++;}} } int main() {int t;scanf("%d", &t);while (t--) {LL k;int m;scanf("%lld%d", &k, &m);LL res = -1;for (int d = 1; d <= 1000; d++) {if (cal(k ^ d, m) == d) {if (res == -1)res = k ^ d;else if (res > (k ^ d))res = k ^ d;}}printf("%lld\n", res);}return 0; }

?

總結

以上是生活随笔為你收集整理的TDL(HDU-6641)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。