HDU 5297 Y sequence
2015-07-24 18:37
501 查看
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).
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
2015 Multi-University Training Contest 1
#include <bits/stdc++.h> using namespace std; #define prt(k) cerr<<#k" = "<<k<<endl typedef long long ll; const int N = 63; int p ; ll n; int r; int sign ; 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; }
相关文章推荐
- UITabBar和UINavigation碰到的几个问题 (系统颜色)
- 使用phpQuery实现批量文件处理
- Weka连接数据库出现No suitable driver found for jdbc:mysql://localhost/dbname
- 150723培训心得(queue)
- HDOJ Integer Inquiry (大数累加)
- HDU 1047 Integer Inquiry
- 给EasyUi的Form添加自动填充部分输入框的方法
- NGUI ScrollView动态添加和删除对象。
- ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn
- 给EasyUi的Form添加自动填充部分输入框的方法
- 2015 Multi-University Training Contest 2 1002 Buildings (HDU5301)
- Flash builder 4.6 下载 破解 序列号【你懂的】
- 基于EasyUI实现自动填充Form内的部分输入框
- 【从零开始学NGUI 】 (八)ScrollView
- Flash builder 4.6 下载 破解 序列号【你懂的】
- UIDatePicker控件
- 2015 Multi-University Training Contest 1 y sequence
- ZOJ_1649_HDU_1242_Rescue
- Snail—UI学习之自定义导航栏NSNavigationController
- ios UITableView代码