hdu多校第六场1008 (hdu6641)TDL 暴力
Posted isakovsky
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hdu多校第六场1008 (hdu6641)TDL 暴力相关的知识,希望对你有一定的参考价值。
题意:
设f(n,m)为比n大的第m个和n互质的数,给定一个k=(f(n,m)-n)xor n和m,求最小的n
题解:
对于给定的m而言,一个k周围合法的n分布的很密,因此在k的邻域暴力搜索即可。
#include<iostream> #define LL long long using namespace std; LL gcd(LL a,LL b) return b==0?a:gcd(b,a%b); bool solve(LL n,LL k,int m) //找到n后面的第m个互质 register LL i; for(i=n+1;;i++) if(gcd(i,n)==1)m--; if(m==0)break; if(((i-n)^n)==k) // printf("%lld",i); return 1; else return 0; int main() int t; scanf("%d",&t); while(t--) LL k; int m; scanf("%lld %d",&k,&m); for(register LL i=max(1ll,k-3000);i<=k+3000;i++) if(solve(i,k,m)) printf("%lld\n",i); goto A; printf("-1\n"); A:;
以上是关于hdu多校第六场1008 (hdu6641)TDL 暴力的主要内容,如果未能解决你的问题,请参考以下文章