HDU 5297 Y sequence
来源:互联网 发布:淘宝客贷怎么才能贷款 编辑:程序博客网 时间:2024/05/17 06:59
Y sequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 658 Accepted Submission(s): 145
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).
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.
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
210 210 3
Sample Output
1314
Author
FZUACM
Source
2015 Multi-University Training Contest 1
#include <bits/stdc++.h>using namespace std;#define prt(k) cerr<<#k" = "<<k<<endltypedef long long ll;const int N = 63;int p[N];ll n; int r;int sign[N];vector<int> rc;vector<int> mi;void get_rc(){ rc.clear(); for (int x : mi) { int n = rc.size(); if (abs(x) > r) break; for (int j=0;j<n;j++) if (abs(x*rc[j]) <= 62) rc.push_back(x*rc[j]); rc.push_back(x); }}ll f(ll n, int r){ if (n==1) return 0; ll ans = n - 1; for (ll x:rc) { ll t = pow(n+0.5, 1.0/abs(x) ) - 1; if (x < 0) ans -= t; else ans += t; } return ans ;}int main(){ for (int i=1;i<N;i++) p[i] = i; for (int i=2;i<N;i++) if (p[i]==i) { for (int j=i+i; j<N; j+=i) p[j] = i; mi.push_back(-i); } int re, ca=1; scanf("%d", &re); while (re--) { scanf("%I64d%d", &n, &r); get_rc(); ll x = n ; while (1) { ll t = f(x, r); if (t >= n) break; x += n - t; } printf("%I64d\n", x); } return 0;}
2 0
- HDU 5297 Y sequence
- HDU 5297 Y sequence
- hdu 5297 Y sequence
- HDU 5297 Y sequence
- HDU 5297 Y sequence
- HDU 5297 Y sequence Y数列
- hdu 5297 Y sequence(容斥)
- 2015 Multi-University Training Contest 1 Hdu 5297 Y sequence
- hdu 5297 Y sequence 容斥+迭代
- HDU 5297(Y sequence-Mobius函数容斥+迭代)
- HDU 5297 Y sequence(容斥+迭代)
- HDU-5297-Y sequence(容斥+迭代)
- HDU 5297 Y sequence (容斥原理 +迭代)
- HDU 5297 Y sequence 数论,迭代,容斥原理
- HDU 5297 Y sequence(数论 迭代 容斥原理)
- 多校第一场 1010 hdu 5297 Y sequence(容斥+二分)
- [多校2015.01.1010 容斥+迭代] hdu 5297 Y sequence
- hdu 5297 - Y sequence( 2015 Multi-University Training Contest 1)容斥原理
- MySQL无法启动几种常见问题小结
- 二值图像轮廓提取
- Xcode 6 国际化
- 游戏引擎中三大及时光照渲染方法介绍(以unity3d为例)
- 如何提高阅读源代码的效率
- HDU 5297 Y sequence
- Android Ion
- 还未理解到php方法()
- java面向对象--06
- java音乐播放之IO流处理
- 二值图像的腐蚀和膨胀
- js简单运动
- Unity3d编辑器拓展
- 【黑马程序员】----java基础---反射