题目链接: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. cut,xargs,sort,tr,rename命令解析

    cut 文件内容查看 显示行中的指定部分,删除文件中指定字段 显示文件的内容,类似于下的type命令. 语法: cut(选项)(参数) 选项: -b:仅显示行中指定直接范围的内容: -c:仅显示行中指 ...

  2. SpringCloud入门(十一):Sleuth 与 Zipkin分布式链路跟踪

    现今业界分布式服务跟踪的理论基础主要来自于 Google 的一篇论文<Dapper, a Large-Scale Distributed Systems Tracing Infrastructu ...

  3. 在服务器本地监控服务端口命令之ss

    在服务器本地监控服务端口命令之ss 当服务器的socket连接数量变得非常大时,无论是使用netstat命令还是直接cat /proc/net/tcp,执行速度都会很慢.可能你不会有 切身的感受,但当 ...

  4. C语言编程入门题目--No.11

    题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月 后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? 1.程序分析: 兔子的规律为数列1,1,2,3, ...

  5. POJ - 2251 Dungeon Master(搜索)

    You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...

  6. The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 XKC's basketball team

    XKC , the captain of the basketball team , is directing a train of nn team members. He makes all mem ...

  7. jQuery如何使用键盘事件,按住空格键完成进度条效果,并终止键盘事件

    jQuery使用键盘事件 keyup:键盘抬起时 keydown:键盘按下时 keypress:键盘按住时 运行下列代码,可以看效果 $(document).keyup(function () { c ...

  8. D - The Bakery CodeForces - 834D 线段树优化dp···

    D - The Bakery CodeForces - 834D 这个题目好难啊,我理解了好久,都没有怎么理解好, 这种线段树优化dp,感觉还是很难的. 直接说思路吧,说不清楚就看代码吧. 这个题目转 ...

  9. FAXCOM和FXSCOMEX 传真编程

    需要引用的dl,如下信息,早起使用的是FXSCOM.DLL,现在微软提供了相应的扩展,其程序集为,FXSCOMEX.dll FXSCOMEX.dll 提供跟加健全的方法,可以说所有关于传真的操作都在这 ...

  10. STM32 时钟树配置快速入门

    layout: post tags: [STM32] comments: true 文章目录 layout: post tags: [STM32] comments: true 为什么要了解时钟树? ...