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 n that (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
Source
2019 Multi-University Training Contest 6

题解:

///
///                            _ooOoo_
///                           o8888888o
///                           88" . "88
///                           (| -_- |)
///                           O\  =  /O
///                        ____/`---'\____
///                      .'  \\|     |//  `.
///                     /  \\|||  :  |||//  \
///                    /  _||||| -:- |||||-  \
///                    |   | \\\  -  /// |   |
///                    | \_|  ''\---/''  |   |
///                    \  .-\__  `-`  ___/-. /
///                  ___`. .'  /--.--\  `. . __
///               ."" '<  `.___\_<|>_/___.'  >'"".
///              | | :  `- \`.;`\ _ /`;.`/ - ` : | |
///              \  \ `-.   \_ __\ /__ _/   .-` /  /
///         ======`-.____`-.___\_____/___.-`____.-'======
///                            `=---='
///        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
///                      Buddha Bless, No Bug !
///
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
#define MAXN 100010
#define ll long longint t, m;
ll k, ans_n;ll cal(ll n, int m)
{if(n < 1)return 0;for(ll i = n + 1;  ; i++)if(__gcd(n, i) == 1){m--;if(m == 0)return i - n;/// (i - n) = (f(n, m) - n) = d
        }
}int main()
{scanf("%d", &t);while(t--){scanf("%lld%d", &k, &m);ans_n = -1;for(int d = 1; d <= 1000; d++){if(cal(k ^ d, m) == d){if(ans_n == -1)ans_n = k ^ d;else if(ans_n > (d ^ k))/// ^ 运算的有优先度小于 <  >  ==  !=ans_n = k ^ d;}}printf("%lld\n", ans_n);}return 0;
}

转载于:https://www.cnblogs.com/RootVount/p/11358647.html

HDU - 6641 TDL(数学)相关推荐

  1. HDU 6641 TDL 异或性质

    定义 f ( n , m ) f(n,m) f(n,m)为比 n n n大的第 m m m个与 n n n互质的数,给出 ( f ( n , m ) − n ) ⊕ n (f(n,m)-n)\oplu ...

  2. 杭电多校 HDU 6641 TDL

    题意:给出一个公式 和公式上的m,k试着求是否有n可以符合上面的公式,若有这输出,没有这输出-1 思路: 1.对于f(n,m)因为与n互质的数很大所以求f(n,m)的时间复杂度并不是很高 2.对于给出 ...

  3. HDUOJ 6641 TDL

    HDUOJ 6641 TDL Problem Description For a positive integer n, let's denote function f(n,m) as the m-t ...

  4. HDU 5914 Triangle 数学找规律

    Triangle 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5914 Description Mr. Frog has n sticks, who ...

  5. Hdu 5339 Untitled (数学思维)

    题意:给一个数a和n个数b1,b2,...,bn. 从n个数中选择一些数重新排列成c1,c2,...,cm使得a%c1%c2%...%cm=0. 如果能选出则输出最少需要几个数,否则输出-1. 分析: ...

  6. HDU 5976 Detachment(数学+结论)

    原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=5976 参考博客:https://blog.csdn.net/qq_34374664/article/d ...

  7. hdu 1593(数学)

    转载标记处:http://www.xuebuyuan.com/2131627.html 往相反的方面跑,但是,最理想的初始位置并不是圆点和圆上的某一点,应该还有更理想的初始逃跑状态.这里有一点需要注意 ...

  8. Circle HDU - 6550 (数学)

    在半径为 1 的圆上有 n 个点,它们也是圆的 n 等分点,将每个相邻的 n 等分点相连,组成了一个正 n边形,现在你可以在圆上再增加一个点,使得新的 n + 1 边形的面积最大,请输出最大面积. I ...

  9. Function HDU - 6546 (数学,贪心)

    wls 有 n 个二次函数 Fi(x) = aix2 + bix + ci (1 ≤ i ≤ n). 现在他想在∑ni=1xi = m 且 x 为正整数的条件下求∑ni=1Fi(xi)的最小值. 请求 ...

最新文章

  1. ZendStudio导入一个已有的网站
  2. Request_继承体系
  3. 验证dropdownlist必选
  4. 利用SOS扩展库进入高阶.NET6程序的调试
  5. 切题 (problem)(线段树+最大流最小割)
  6. React开发(202):react代码分割之import导入导出
  7. eventfd以及epoll原理分析
  8. LeetCode 2169. 得到 0 的操作数
  9. 修改端口_如何修改服务器的远程端口
  10. unity mysql增删改查,XML的使用,增删改查(Unity中的)
  11. unique函数_包含虚函数的类应该有虚析构函数或保护析构函数?
  12. CF914D Bash and a Tough Math Puzzle
  13. 程序员必备神器(FastStoneCapture)
  14. Swift_学习笔记_调用ObjectiveC方法
  15. 如何在 WordPress 中启用WebP 图片?webp有什么优势?
  16. CorelDRAW2023安装下载教程精简版矢量绘图软件
  17. 玩转“抖音”的10种内容策划套路!
  18. 无监督学习-案例分析:利率期限结构
  19. 量子计算磁共振原型机被激光脉冲原型机淘汰
  20. GDB调试指南-启动调试

热门文章

  1. [JZOJ5863] 【NOIP2018模拟9.11】移动光标
  2. 原生JS封装时间运动函数
  3. Python包的相对导入时出现问题解决
  4. Xamarin.Forms中使用LiteDB分页
  5. VS2012 打包部署程序
  6. Hadoop常见面试45问
  7. [9]UITableView表视图1
  8. 手势模型和Angular Material的实现
  9. [ASP.net]ASP.net的RUL重写
  10. 计算机网络实验3:网络设备基本配置