HDU 5297
用x ^ (1 / n) 来求个数,容斥原理 , Num会向后移动, 迭代到不再变化,退出循环
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const int Primes[] = {-2,-3,-5,-7,-11,-13,-17,-19,-23,-29,-31,-37,-41,-43,-47,-53,-59,-61,-67,-71};
vector<int> R_number;
void GetR(LL R) {
R_number.clear();
for(int i = 0; abs(Primes[i])<= R; ++i) {
int tmp = Primes[i];
int Num = R_number.size();
for(int j = 0; j < Num; ++j) {
if(abs(R_number[j]*tmp) <= 63)
R_number.push_back(tmp * R_number[j]);
}
R_number.push_back(Primes[i]);
}
}
LL Cnt(LL N) {
//GetR(R);
if(N == 1) return 0;
LL cnt = N;
for(int i = 0; i < R_number.size(); ++i) {
LL tmp = LL (pow(N+0.5, 1.0/abs(R_number[i])) - 1);
if(R_number[i] < 0) cnt -= tmp;
else cnt += tmp;
}
return cnt - 1;
}
void Solve(LL N,LL R) {
GetR(R);
LL ans = N;
while(1) {
LL tmp = Cnt(ans);
if(tmp == N) break;
ans += N - tmp;
}
printf("%lld\n",ans);
}
int main() {
int t;
scanf("%d",&t);
while(t--) {
LL n,r;
scanf("%I64d %I64d",&n,&r);
Solve(n,r);
}
return 0;
}
HDU 5297的更多相关文章
- HDU 5297 Y sequence 容斥 迭代
Y sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5297 Description Yellowstar likes integer ...
- HDU - 5297:Y sequence (迭代&容斥)
Yellowstar likes integers so much that he listed all positive integers in ascending order,but he hat ...
- HDU 5297 Y sequence Y数列
题意:给定正整数n和r.定义Y数列为从正整数序列中删除全部能表示成a^b(2 ≤ b ≤ r)的数后的数列,求Y数列的第n个数是多少. 比如n = 10. r = 3,则Y数列为2 3 5 6 7 1 ...
- [2015hdu多校联赛补题]hdu5297 Y sequence
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5297 题意:给你一个所有正整数的序列,然后去掉满足x^(2~r)的所有数(x为所有正整数,r>= ...
- 2015 Multi-University Training Contest 1 题解&&总结
---------- HDU 5288 OO’s Sequence 题意 给定一个数列(长度<$10^5$),求有多少区间[l,r],且区间内有多少数,满足区间内其它数不是他的约数. 数的范围$ ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
随机推荐
- 查看swap占用情况
查看swap被占用的情况 #!/bin/bash # Get current swap usage for all running processes # Erik Ljungstrom 27/05/ ...
- Android允许在UI线程中使用网络访问
StrictMode.ThreadPolicy policy=new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode ...
- C# 使用 log4net 记录日志
Ø 前言 在一般的开发应用中,都会涉及到日志记录,用于排查错误 或 记录程序运行时的日志信息.log4net 库是 Apache log4j 框架在 Microsoft .NET 平台的实现,是一个 ...
- Jenkins pipeline shared library
Jenkinsfile https://jenkins.io/doc/book/pipeline/jenkinsfile/ Jenkins Pipeline is a suite of plugins ...
- bzoj 3620 暴力KMP
十分暴力的KMP,枚举左端点,在向右侧推进的同时,取较小的la保证条件,n方暴力 #include<bits/stdc++.h> #define rep(i,j,k) for(int i= ...
- springboot06-swagger2 自动化api文档
1.springboot 项目中添加swagger2依赖: <dependency> <groupId>org.springframework.boot</groupId ...
- blender 操作快捷键
选择:a: 全选OR取消选择b: 矩形选择c: 画刷选择ctrl+左键:套索选择ctrl+alt+右键 : 环边选择ctrl+右键:ctrl+tab:切换 点,线,面 选择模式ctrl+- 选择/收缩 ...
- c/cpp枚举练习
enum aa{ am,bm }ha=bm,hb; int main(int argc, char *argv[]){ printf("%d %d",ha,am); //1 1 ; ...
- Codeforces 1065F(树形dp)
题目链接 题意 给一棵树,进行如下操作,如果当前点非叶子,则往子树移动,否则最多向上移动k次,问从根节点开始最多访问多少叶子 思路 预处理出每个点最多能“白嫖”到几个叶子,根据下一个点的状态更新最优方 ...
- ES5新增内容
一.数组API实际开发中forEach和map会多一些=>是es6语法中的arrow function举例:(x) => x + 6相当于function(x){return x + 6; ...