Tiny Wong the chef used to be a mathematics teacher in a senior high school. At that time, he always used to tell his students that when there is a square root of some number in one’s final result, it should be simplified by factoring out the largest square divisor of this number. For example, √ 12  = 2 √ 3 . Therefore, if an integer n has a square divisor, i.e. there is a number d > 1 such that d2 divides n, then the square root of n needs to be simplified.

Tiny himself should generate for homework some number whose square root needs simplifying. Since he used to major in Computer Science, he prefers random numbers. Therefore, he randomly chose a number n and decided to use the n-th smallest number whose square root needs simplifying in today’s homework.

Since the n-th such number is too large for him to deal with, Tiny Wong is lost in thought. Would you please help him?

Input

The first and only line of the input contains a single integer n.

Note: the number n is not fixed for each test case. Instead, it will be generated dynamically, so it may be different for each run of your program. For each test case, n is generated in the following way: we have two fixed numbers L and Rn will be chosen uniformly at random from all integers between L and R inclusive.

Note 2: Due to dynamically generated test cases, the problem is technically configured as interactive, thus reading until EOF will not work. Attempting to use any input method that expects EOF at the end will result in TLE verdict.

Output

Print a single line containing one integer — the n-th number whose square root needs simplifying.

Constraints

      1 ≤

n

      ≤ 10

18

Subtasks

Subtask #1 (6 points): 1 ≤ n ≤ 107

Subtask #2 (17 points): 1 ≤ n ≤ 1014

Subtask #3 (27 points): 1 ≤ n ≤ 1016

Subtask #4 (50 points): 1 ≤ n ≤ 1018

Example

Input:

4

Output:

12

Explanation

The first 4 numbers whose square roots need simplifying are 4, 8, 9 and 12.

 思路:见:https://blog.csdn.net/gjghfd/article/details/79137620 。

//求第N个含平方因子数时,可以把二分范围限制到如此,而筛不含平方因子数的时候,可以把上界限制到2N。
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
const double pi=acos(-1.0);
map<int,int>M;
int mu[maxn],mu2[maxn],p[maxn>>],cnt; bool vis[maxn];
void init()
{
mu[]=; mu2[]=;
rep(i,,maxn-){
if(!vis[i]) p[++cnt]=i,mu[i]=-;
for(int j=,t;j<=cnt&&(t=p[j]*i)<maxn;j++){
mu[t]=-mu[i]; vis[t]=; //少做几次乘法
if(!(i%p[j])) {mu[t]=; break;}
}
}
rep(i,,maxn-) mu2[i]=mu2[i-]+(!mu[i]?:),mu[i]+=mu[i-];
}
int musum(int x)//莫比乌斯前缀和
{
if(x<maxn) return mu[x];
if(M.count(x))return M[x];
int res=;
for(int i=,j;i<=x;i=j+){
int k=x/i; j=x/k;
res-=musum(k)*(j-i+);
}
return M[x]=res;
}
ll nonfsum(ll x) //无平方因子前缀和
{
if(x<maxn) return mu2[x];
ll i=,res=,lst=,R,t;
for(;i*i*i<=x;i++) res+=(x/(i*i))*(mu[i]-lst),lst=mu[i];
for(res-=(t=x/(i*i))*lst;t;t--) res+=musum(sqrt(x/t));
return res;
}
int main(){
init();
ll N,ans,l,r,Mid;
scanf("%lld",&N);
l=N/(-/pi/pi),r=l+,l-=; //大致范围
l=max(l,1LL);
while(l<=r){
Mid=l+r>>;
if(Mid-nonfsum(Mid)>=N) ans=Mid,r=Mid-;
else l=Mid+;
}
printf("%lld\n",ans);
return ;
}

CodeChef - SQRGOOD:Simplify the Square Root (求第N个含平方因子数)的更多相关文章

  1. Project Euler 80:Square root digital expansion 平方根数字展开

    Square root digital expansion It is well known that if the square root of a natural number is not an ...

  2. Project Euler 57: Square root convergents

    五十七.平方根收敛(Square root convergents) 二的平方根可以表示为以下这个无穷连分数: \[ \sqrt 2 =1+ \frac 1 {2+ \frac 1 {2 +\frac ...

  3. Codeforces 715A. Plus and Square Root[数学构造]

    A. Plus and Square Root time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  4. Codeforces 612E - Square Root of Permutation

    E. Square Root of Permutation A permutation of length n is an array containing each integer from 1 t ...

  5. Codeforces 715A & 716C Plus and Square Root【数学规律】 (Codeforces Round #372 (Div. 2))

    C. Plus and Square Root time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  6. (Problem 57)Square root convergents

    It is possible to show that the square root of two can be expressed as an infinite continued fractio ...

  7. Square Root

    Square RootWhen the square root functional configuration is selected, a simplified CORDIC algorithm ...

  8. Codeforces Round #372 (Div. 1) A. Plus and Square Root 数学题

    A. Plus and Square Root 题目连接: http://codeforces.com/contest/715/problem/A Description ZS the Coder i ...

  9. Plus and Square Root

    ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, ...

随机推荐

  1. Django 进阶篇之 CSRF,COOIKE,SESSION

    1.CSRF(Cross Site Request Forgery, 跨站域请求伪造) CSRF 背景与介绍 CSRF(Cross Site Request Forgery, 跨站域请求伪造)是一种网 ...

  2. PHP日期与时间戳转换

    设置时区 在php.ini中找到data.timezone去掉它前面的;号,然后设置data.timezone = "Asia/Shanghai"; 或者 ini_set('dat ...

  3. 17 南宁区域赛 F - The Chosen One 【规律】

    题目链接 https://nanti.jisuanke.com/t/19972 题意 给出一个n 然后将 n 个数 标号为 1 -> n 按顺序排列 每次抽掉 奇数位的数 然后求最后剩下那个数字 ...

  4. 安装好MySQL后就开始学习如何后台创建自己的数据库吧!

    MySQL创建数据库的方式不像SQL Server那样有图形界面,而是使用DOS窗口创建的,接下来就是创建MySQL数据库的具体步骤. ↓↓↓↓↓↓↓↓      ↓↓↓↓↓↓↓↓      ↓↓↓↓ ...

  5. Ubuntu启动自动登录并启动程序

    最近在研究Ubuntu,需要在系统启动之后自动登录,并且启动某个程序. 手上拿到的系统只有一个空桌面,其他嘛也没有,鼠标右键也不管用.于是借助自己的虚拟机研究发现,自动启动程序配置文件在: /home ...

  6. nodejs/REPL环境命令行操作命令

    1,输入node 进入node[REPL]环境 2,按两次[ctrl+c]退出node[REPL]环境 3,上箭头会查找上次输入的命令 4,cls清屏 5,tab键会自动补全路径 6,REPL环境

  7. groupby和agg的使用

    先来看一段代码: 分析下groupby和agg的联合使用: reset_index()表示重新设置索引 agg传进来的统计特征: 按照A这一列作聚合,C这一列作统计 注意:df = df.groupb ...

  8. 关于Kinect音频开发的探究

    1.笔者在<Kinect体感程序设计入门>(王森著)的这本书中看到可以使用powershell和COM对象无缝整合,轻松的使用windows系统自带的语音合成功能. 步骤:•打开进入pow ...

  9. RHCE学习笔记 管理1 (第一、二章)

    第一章 命令行访问 1.Ctrl+alt+F2~F6 切到虚拟控制台,ctrl+alt+F1 回到图形界面 2.格式 : 命令 选项 参数 [] 为可选项目            ...表示该项目任意 ...

  10. JavaWeb基础

    1.Servlet: Servlet是JavaWeb的3大组件之一,是把url请求转为后台处理的具体类,此类必须实现Servlet接口,一把实际使用时无须我们实现,我们直接使用JavaEE的HTTPS ...