Y sequence

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 667    Accepted Submission(s): 147

Problem Description
Yellowstar likes integers so much that he listed all positive integers in ascending order,but he hates those numbers which can be written as a^b (a, b are positive integers,2<=b<=r),so he removed them all.Yellowstar calls the sequence that formed by the rest integers“Y sequence”.When r=3,The first few items of it are:
2,3,5,6,7,10......
Given positive integers n and r,you should output Y(n)(the n-th number of Y sequence.It is obvious that Y(1)=2 whatever r is).
 
Input
The first line of the input contains a single number T:the number of test cases.
Then T cases follow, each contains two positive integer n and r described above.
n<=2*10^18,2<=r<=62,T<=30000.
 
Output
For each case,output Y(n).
 
Sample Input
2
10 2
10 3
 
Sample Output
13
14
 
Author
FZUACM
 
Source
 
解题:传说中的容斥原理。
 
先计算1到n间有多少个数被删除了,那么我们就还需要m=n+删除的数目,看看又又多少个删除了,看看剩下的是不是刚好n个,否则补上n - 剩下的个数,继续搞
 
处理1的时候,先把1都不算,最后才算,奇数个素因子的乘积那么要加上,偶数个素因子的乘积要减去
 
参考了这位博主的写法
 
可以由$\sqrt[i]{a}$得出范围内指数是i的元素的个数  
 #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int p[] = {, , , , , , , , , , , , , , , , , , };
vector<int>d;
LL n,r;
void init() {
d.clear();
for(int i = ; p[i] <= r; ++i) {
for(int j = d.size()-; j >= ; --j)
if(abs(d[j]*p[i]) <= ) d.push_back(-d[j]*p[i]);
d.push_back(p[i]);
}
}
LL calc(LL x){
if(x == ) return ;
LL ret = x;
for(int i = d.size()-; i >= ; --i){
LL tmp = pow(x+0.5,1.0/abs(d[i])) - ;
if(d[i] < ) ret += tmp;
else ret -= tmp;
}
return ret-;
}
LL solve(){
init();
LL ret = n;
while(true){
LL tmp = calc(ret);
if(tmp == n) break;
ret += n - tmp;
}
return ret;
}
int main() {
ios::sync_with_stdio(false);
int kase;
cin>>kase;
while(kase--){
cin>>n>>r;
cout<<solve()<<endl;
}
return ;
}

2015 Multi-University Training Contest 1 y sequence的更多相关文章

  1. 2018 Multi-University Training Contest 1 Balanced Sequence(贪心)

    题意: t组测试数据,每组数据有 n 个只由 '(' 和 ')' 构成的括号串. 要求把这 n 个串排序然后组成一个大的括号串,使得能够匹配的括号数最多. 如()()答案能够匹配的括号数是 4,(() ...

  2. HDU - 6304(2018 Multi-University Training Contest 1) Chiaki Sequence Revisited(数学+思维)

    http://acm.hdu.edu.cn/showproblem.php?pid=6304 题意 给出一个数列的定义,a[1]=a[2]=1,a[n]=a[n-a[n-1]]+a[n-1-a[n-2 ...

  3. 2018 Multi-University Training Contest 1-1002 -Balanced Sequence(括号匹配+贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6299 题目: 题意:t组数据,每组数据给你一个n表示给你n个括号串,这n个括号串之间进行组合,求能够匹 ...

  4. 2015 Multi-University Training Contest 1 - 10010 Y sequence

    Y sequence Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=5297 Mean: 有连续数列A={1,2,3,4,5,6, ...

  5. 2015 Multi-University Training Contest 2 hdu 5306 Gorgeous Sequence

    Gorgeous Sequence Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...

  6. hdu 5288 OO’s Sequence(2015 Multi-University Training Contest 1)

    OO's Sequence                                                          Time Limit: 4000/2000 MS (Jav ...

  7. 2015 Multi-University Training Contest 6 hdu 5357 Easy Sequence

    Easy Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  8. 2015 Multi-University Training Contest 1 OO’s Sequence

    OO’s Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  9. 2015 Multi-University Training Contest 8 hdu 5390 tree

    tree Time Limit: 8000ms Memory Limit: 262144KB This problem will be judged on HDU. Original ID: 5390 ...

随机推荐

  1. CefSharp的简单应用,制作自动学习视频软件(基于Chromium)

    CefSharp在NuGet的简介是“The CefSharp Chromium-based browser component”,机翻的意思就是“基于Cefsharp Chromium的浏览器组件” ...

  2. 发个ZKW线段树板子测试一下代码高亮

    是我,Long time no see          --Jim 先安利 Wolves  歌手:Madilyn Bailey http://music.163.com/song/524149464 ...

  3. JS中的DOM操作怎样添加、移除、移动、复制、创建和查找节点

    DOM操作怎样添加.移除.移动.复制.创建和查找节点? (1)创建新节点 createDocumentFragment() //创建一个DOM片段 createElement() //创建一个具体的元 ...

  4. tcpdump的使用以及参数详解

    平时分析客户端和服务器网络交互的问题时,很多情况下需要在客户端和服务器抓包分析报文.一般win下抓包使用WireShark即可,但是linux下就需要用到tcpdump了,下面是一些对于tcpdump ...

  5. -bash: wget 未找到命令的解决办法

    在Linux操作系统中,我们会经常要用到wget下载文件.wget非常稳定,它在带宽很窄的情况下和不稳定网络中有很强的适应性. 在linux中使用wget时,若报-bash: wget: comman ...

  6. Set里的元素是不能重复的,那么用什么方法来区分重复与否呢? 是用==还是equals()? 它们有何区别?

    Set里的元素是不能重复的,那么用什么方法来区分重复与否呢? 是用==还是equals()? 它们有何区别? 1.什么是Set?(what) Set是Collection容器的一个子接口,它不允许出现 ...

  7. ASP.NET-internat身份验证

    ASP.NET-internat身份验证默认在webconfig中配置的代码是这样的 <system.web> <compilation debug="true" ...

  8. 【转】工具系列:IntelliJ IDEA (Mac) 运行速度优化

    转自工具系列:IntelliJ IDEA (Mac) 运行速度优化 感谢该作者解决了我使用idea debug很慢的问题 背景 IDEA 下运行程序,经常假死 5 s,作为 Mac 怎么能允许暂停 5 ...

  9. 数据结构 - 树形选择排序 (tree selection sort) 具体解释 及 代码(C++)

    树形选择排序 (tree selection sort) 具体解释 及 代码(C++) 本文地址: http://blog.csdn.net/caroline_wendy 算法逻辑: 依据节点的大小, ...

  10. iOS 从各种效果图颜色标注生成 UIColor

    iOS 从各种效果图颜色标注生成 UIColor 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公 ...