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 ...
随机推荐
- 关于CPU的User、Nice、System、Wait、Idle各个参数的解释
使用Ganglia监控整个Hadoop集群,看到Ganglia采集的各种指标:CPU各个具体的指标含义解释如下: ①CPU(监测到的master主机上的CPU使用情况) 从图中看出,一共有五个关于CP ...
- you have mixed tabs and spaces.Fix This屏蔽
这个功能很影响vs的速度,解决办法(VS2010版本为例),将Fix Mixed Tabs改为OFF即可.
- z-index设置后导致遮罩层显示跳动问题
如图,1,3为top,bottom div,2为iscroll,4为遮罩层,如果1设置z-index后,不设置遮挡不住2,遮罩层4弹出会卡顿,既不设置z-index,又能遮挡iscroll的办法是在h ...
- SpringBoot入门笔记(一)、HelloWorld
本文是一篇SprintBoot学习入门笔记 1.打开Eclipse,版本为Oxygen 4.7.0 2.新建项目NewProject->MavenProject->Next->Nex ...
- IDEA 远程调试 Tomcat 和 Debugger
一般来说我们本地环境使用Tomcat,生产环境使用GlassFish. 准备工作 明确远程服务器的 IP 地址,比如:192.168.92.128 关掉服务器防火墙:service iptables ...
- SQL Server 远程备份详解
例1: 有A数据库服务器,B本机: 我现在想通过在B机器上通过代码调用SQL来执行A数据库的备份到B机器上 调用的SQL语句为:Backup Database MYDATABASE To Disk=' ...
- Java SE之网络编程:知识框架
- 怎样远程访问 MySQL
比如我在PC上安装有 phpmyadmin, 图形界面很友好,我的MySQL 在一台Centos 7.5服务器上,很自然的想到用phpmyadmin 去登录linux上的MySQL. 但是折腾了很久也 ...
- (7)Java数据结构--集合map,set,list详解
MAP,SET,LIST,等JAVA中集合解析(了解) - clam_clam的专栏 - CSDN博---有颜色, http://blog.csdn.net/clam_clam/article/det ...
- ASP.NET - ADO.NET框架
ADO.NET(ActiveX Data Objects) ADO.NET是一个COM组件库,用于在使用Microsoft技术的代码中访问数据库. SQL数据操作类 SqlConnection类(Sy ...