Happy 2006
Time Limit: 3000MS | Memory Limit: 65536K | |
Description
Now your job is easy: for the given integer m, find the K-th element which is relatively prime to m when these elements are sorted in ascending order.
Input
Output
Sample Input
2006 1
2006 2
2006 3
Sample Output
1
3
5
分析:第k个与m互质的数,对m求素因子后二分容斥即可;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define sys system("pause")
const int maxn=1e5+;
using namespace std;
inline ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
inline ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
inline void umax(ll &p,ll q){if(p<q)p=q;}
inline void umin(ll &p,ll q){if(p>q)p=q;}
inline ll read()
{
ll x=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,k,t,cnt,fac[maxn],cas;
ll x,y;
void init(int x)
{
cnt=;
if(x%==){
fac[++cnt]=;
while(x%==)x/=;
}
for(int i=;(ll)i*i<=x;i+=)
{
if(x%i==)
{
fac[++cnt]=i;
while(x%i==)x/=i;
}
}
if(x>)fac[++cnt]=x;
}
ll gao(ll x)
{
ll ret=;
for(int i=;i<(<<cnt);i++)
{
ll num=,now=;
for(int j=;j<cnt;j++)
{
if(i&(<<j))
{
++num;
now*=fac[j+];
}
}
if(num&)ret+=x/now;
else ret-=x/now;
}
return x-ret;
}
int main()
{
int i,j;
while(~scanf("%d%d",&n,&m))
{
init(n);
ll l=,r=1e18,ret;
while(l<=r)
{
ll mid=l+r>>;
if(gao(mid)>=m)ret=mid,r=mid-;
else l=mid+;
}
printf("%lld\n",ret);
}
return ;
}
Happy 2006的更多相关文章
- BZOJ 2006: [NOI2010]超级钢琴
2006: [NOI2010]超级钢琴 Time Limit: 20 Sec Memory Limit: 552 MBSubmit: 2613 Solved: 1297[Submit][Statu ...
- #Deep Learning回顾#之2006年的Science Paper
大家都清楚神经网络在上个世纪七八十年代是着实火过一回的,尤其是后向传播BP算法出来之后,但90年代后被SVM之类抢了风头,再后来大家更熟悉的是SVM.AdaBoost.随机森林.GBDT.LR.FTR ...
- MySQL(Navicat)运行.sql文件时报错:[Err] 2006 - MySQL server has gone away 的解决方法
背景: 今天导入一个数据量很大的.sql文件时,报错: 原因: 可能是sql语句过长,超过mysql通信缓存区最大长度. 解决:1. 编辑 MySQL 安装目录下的 my.ini,在最后添加以下内容: ...
- MySQL导入sql脚本错误:2006 - MySQL server has gone away
到如一些小脚本很少报错,但最近导入一个10+M的SQL脚本,却重复报错: Error occured at:2014-03-24 11:42:24 Line no.:85 Error Code: 20 ...
- BizTalk开发系列(三) 单机环境下的BizTalk Server 2006 R2安装
大部分的开发环境都是在单机环境下进行的,今天整理了一下BizTalk Server 2006 R2在单机环境下的安装步骤. 1. 软件需求 在独立服务器中完整安装BizTalk Server 2006 ...
- (转自http://www.blogjava.net/moxie/archive/2006/10/20/76375.html)WebWork深入浅出
(转自http://www.blogjava.net/moxie/archive/2006/10/20/76375.html) WebWork深入浅出 本文发表于<开源大本营> 作者:钱安 ...
- 【mysql】之MySQL导入sql脚本错误:2006 - MySQL server has gone away
到如一些小脚本很少报错,但最近导入一个10+M的SQL脚本,却重复报错: Error occured at:2014-03-24 11:42:24Line no.:85Error Code: 2006 ...
- BZOJ 2006 超级钢琴(划分树+优先队列)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2006 题意: 给出一个数列A,L,R,构造出一个新的集合,集合中的数字为A中任意连续t( ...
- NET程序的破解--静态分析(Xenocode Fox 2006 Evaluation)
NET程序已经红红火火的兴起,就象LINUX一样势不可挡的涌来.作为一名Cracker,你会选择躲避吗?嘿嘿,对俺而言,挑战更富有趣味. 破解好几个.NET的程序了,一直想写出来,只是时间问题,所以拖 ...
- Bzoj 2006: [NOI2010]超级钢琴 堆,ST表
2006: [NOI2010]超级钢琴 Time Limit: 20 Sec Memory Limit: 552 MBSubmit: 2222 Solved: 1082[Submit][Statu ...
随机推荐
- Linux(redhat 5.8)下 安装jetty 部署 使用
首先须要安装JDK,自行解决 下载jetty安装包http://dist.codehaus.org/jetty/ 我下载的是8.1.15 tar -xzvf *.tar.gz 解压完之后,基本就能够用 ...
- oc49--@class
// Person.h #import <Foundation/Foundation.h> @class Car; //#import "Car.h" // 由于imp ...
- 背包问题的方案总数 P1474 货币系统
背包问题的方案总数 对于一个给定了背包容量.物品费用.物品间相互关系(分组.依赖等)的背包问题,除了再给定每个物品的价值后求可得到的最大价值外,还可以得到装满背包或将背包装至某一指定容量的方案总数. ...
- 洛谷 P1081 开车旅行 —— 倍增
题目:https://www.luogu.org/problemnew/show/P1081 真是倍增好题! 预处理:f[i][j] 表示从 i 点开始走 2^j 次 AB (A,B各走一次)到达的点 ...
- C - Xenia and Ringroad
Problem description Xenia lives in a city that has n houses built along the main ringroad. The ringr ...
- C# html生成PDF遇到的问题,从iTextSharp到wkhtmltopdf
我们的网站业务会生成一个报告,用网页展示出来,要有生成pdf并下载的功能,关键是生成pdf. 用内容一段段去拼pdf,想想就很崩溃,所以就去网上找直接把html生成pdf的方法. 网上资料大部分都是用 ...
- 初次尝试PHP——一个简单的对数据库操作的增删改查例子
第一次学习PHP,很多人说PHP是最好的语言,学习了一点点,还不敢说这样的话,不过确实蛮好用的. 做了一个简单的对数据库的增删改查的操作,主要是将四种操作写成了独立的函数,之后直接调用函数.以下是代码 ...
- IN、EXISTS的相关子查询用INNER JOIN 代替--性能优化
如果保证子查询没有重复 ,IN.EXISTS的相关子查询可以用INNER JOIN 代替.比如: IN.EXISTS的相关子查询用INNER JOIN 代替--sql2000性能优化
- VHDL之code structure
1 VHDL units VHDL code is composed of at least 3 fundamental sections: 1) LIBRARY declarations: Con ...
- web前端技术与原生技术的竞争, 及未来的发展
用户界面领域: web技术与原生技术之争 除了浏览器中运行之外, html5的技术也在app领域和移动端的安卓, iOS, 以及桌面端的window, linux以及OS X展开了竞争. 同样属于用户 ...