题目链接:https://vjudge.net/problem/Gym-101612L

知识点:  数学

题目大意:

  给一个数 \(n(1 \le n \le 10^{18})\),要求将 \(n\) 分解成 \(a^{p}(a+1)^{q}\),问有多少种分解方案。

解题思路:

  如果 \(n\) 可以表示成 \(2^{t}\) 的形式,则有无限种分解方案,因为此时 \(n\) 可以分解成 \(1^{p} \times 2^{t}\) 的形式,其中 \(p\) 可以为任意整数。

  接下来讨论有限种分解方案的情况。

  \(n=a^{p}(a+1)^{q}\) 中的 \(a\) 近似等于 \(\lfloor ^{p+q} \sqrt{n} \rfloor = \lfloor ^{r} \sqrt{n} \rfloor\),其中 \((1 \le r \le log_2(n) \le 64)\),用求出的近似的 \(a\) 和 \(a+1\) 去尝试分解 \(n\) 即可。

AC代码:

 #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
vector<vector<LL> > ans; void solve(LL n,LL a){//试分解函数
vector<LL> ret;
while(n%a==){
ret.push_back(a);
n/=a;
}
while(n%(a+)==){
ret.push_back(a+);
n/=(a+);
}
if(n==){
ans.push_back(ret);
}
}
int main(){
freopen("little.in", "r", stdin);
freopen("little.out", "w", stdout);
LL n;
scanf("%lld",&n);
if((n&(n-))==){ //判断 n 是否是 1<<x 的形式的数
printf("-1\n");
return ;
} solve(n,n);
for(int s=;s<=;s++){
LL r=(LL)pow(n,1.0/(double)s);
for(int j=-;j<=;j++){
if(r+j>)
solve(n,r+j);
}
}
sort(ans.begin(),ans.end());
ans.erase(unique(ans.begin(),ans.end()),ans.end()); //去重 printf("%d\n",ans.size());
for(int i=;i<ans.size();i++){
printf("%d",ans[i].size());
for(int j=;j<ans[i].size();j++){
printf(" %lld",ans[i][j]);
}
printf("\n");
}
return ;
}

  

Gym101612L Little Difference的更多相关文章

  1. Java 堆内存与栈内存异同(Java Heap Memory vs Stack Memory Difference)

    --reference Java Heap Memory vs Stack Memory Difference 在数据结构中,堆和栈可以说是两种最基础的数据结构,而Java中的栈内存空间和堆内存空间有 ...

  2. What's the difference between a stub and mock?

    I believe the biggest distinction is that a stub you have already written with predetermined behavio ...

  3. [转载]Difference between <context:annotation-config> vs <context:component-scan>

    在国外看到详细的说明一篇,非常浅显透彻.转给国内的筒子们:-) 原文标题: Spring中的<context:annotation-config>与<context:componen ...

  4. What's the difference between <b> and <strong>, <i> and <em> in HTML/XHTML? When should you use each?

    ref:http://stackoverflow.com/questions/271743/whats-the-difference-between-b-and-strong-i-and-em The ...

  5. difference between forward and sendredirect

    Difference between SendRedirect and forward is one of classical interview questions asked during jav ...

  6. Add Digits, Maximum Depth of BinaryTree, Search for a Range, Single Number,Find the Difference

    最近做的题记录下. 258. Add Digits Given a non-negative integer num, repeatedly add all its digits until the ...

  7. MySQL: @variable vs. variable. Whats the difference?

    MySQL: @variable vs. variable. Whats the difference?   up vote351down votefavorite 121 In another qu ...

  8. Distribute numbers to two “containers” and minimize their difference of sum

    it can be solved by Dynamical Programming.Here are some useful link: Tutorial and Code: http://www.c ...

  9. difference between append and appendTo

    if you need append some string to element and need set some attribute on these string at the same ti ...

随机推荐

  1. mac OS nvm 常用命令

    nvm install stable ## 安装最新稳定版 node,当前是node v10.15.0 (npm v6.4.1) nvm install <version> ## 安装指定 ...

  2. Web全栈AngularJS

    百度云盘下载 AngularJS是人类首个大规模使用的MVC框架,能够帮助程序员将绝大部分精力集中在核心业务逻辑上,从而大幅提高开发效率. 阶段2:Controller Controller是Angu ...

  3. android自定义View&自定义ViewGroup(上)

    一般自定义view需要重写的方法 void onMeasure(int widthMeasureSpec, int heightMeasureSpec) void onSizeChanged(int ...

  4. 通用权限管理系统组件 (GPM - General Permissions Manager)

    有的公司开发人员只那么几个,一个人支撑整个公司所有的IT系统实在有点累,不想自己写权限系统了,自己琢磨不也是要花时间和精力,要为此付出多少时间和汗水阿,细细的皱纹不知要多多少呢,重复建设不是白白浪费生 ...

  5. 使用SWIG将C++接口转换成Java接口

    PS:此文章仅作为个人记录使用,代码属于私密,故无法公开: 以C++类classifier为例,文件保存于百度网盘 https://pan.baidu.com/s/1c2AwhaS(需密码) 系统:U ...

  6. H5 -- 取消a标签在点击时的背景颜色

    原文链接:点我 1.取消a标签在移动端点击时的蓝色 a { -webkit-tap-highlight-color: rgba(255, 255, 255, 0); -webkit-user-sele ...

  7. 数据库SQL语言从入门到精通--Part 3--SQL语言基础知识

    数据库从入门到精通合集(超详细,学习数据库必看) 一.关系 单一的数据结构----关系 现实世界的实体以及实体间的各种联系均用关系来表示 逻辑结构----二维表 从用户角度,关系模型中数据的逻辑结构是 ...

  8. postman(参数化)

    一.参数化 1.新建csv文件 2.csv文件中输入变量名和参数 3.postman中新增接口,并设置变量 4.选择进入runner页面 方法一 方法二 5.导入参数化csv格式文件,点击run It ...

  9. 数据库——数据库SQL语句大全,最常用的SQL语句

    检索数据 检索单个列: SELECT pname FROM product 检索多个列: SELECT pname,market_price,is_hot FROM product 检索所有列: SE ...

  10. Navicat12.1系列安装,破解以及破解navicat报错的解决方案

    由于上课的需要,我们必须自己下载并安装 Navicat Premium 12,虽然安装过程很简单,但是安装后的navicat只能试用,并没有永久激活,然而我还想永久使用,所以就各种百度,因为不断地遇到 ...