Gym101612L Little Difference
题目链接: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的更多相关文章
- Java 堆内存与栈内存异同(Java Heap Memory vs Stack Memory Difference)
--reference Java Heap Memory vs Stack Memory Difference 在数据结构中,堆和栈可以说是两种最基础的数据结构,而Java中的栈内存空间和堆内存空间有 ...
- 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 ...
- [转载]Difference between <context:annotation-config> vs <context:component-scan>
在国外看到详细的说明一篇,非常浅显透彻.转给国内的筒子们:-) 原文标题: Spring中的<context:annotation-config>与<context:componen ...
- 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 ...
- difference between forward and sendredirect
Difference between SendRedirect and forward is one of classical interview questions asked during jav ...
- 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 ...
- MySQL: @variable vs. variable. Whats the difference?
MySQL: @variable vs. variable. Whats the difference? up vote351down votefavorite 121 In another qu ...
- 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 ...
- 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 ...
随机推荐
- HTML中使用CSS样式(上)
在每一个标签上都可以设置style属性,这就是CSS样式: <div style="height:48px;border: 1px solid red;text-align:cente ...
- socket编程-多个客户端向服务器发送人脸照片,服务器返回识别结果(服务器使用多线程)...
recognition.py import numpy as np import face_recognition import os class recognition: def __init__( ...
- CentOS配置Tomcat监听80端口,虚拟主机
2019独角兽企业重金招聘Python工程师标准>>> Tomcat更改默认端口为80 更改的配置文件是: /usr/local/tomcat/conf/server.xml [ro ...
- pod setup命令失败解决方法
最近运行pod setup出现以下问题: remote: Compressing objects: 100% (34/34), done.error: RPC failed; curl 56 SSLR ...
- nginx 反向代理转发导致css,js,图片失效
为什么80%的码农都做不了架构师?>>> 需要添加以下配置 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { proxy_pass htt ...
- C# 对 TCP 客户端的状态封装
TCP客户端连接TCP服务器端有几种应用状态: 与服务器的连接已建立 与服务器的连接已断开 与服务器的连接发生异常 应用程序可按需求合理处理这些逻辑,比如: 连接断开后自动重连 连接断开后选择备用地址 ...
- Mbatis逆向工程常遇错误
org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession.### The error may e ...
- 程序员还在用360,腾讯电脑管家清理注册表,清理垃圾?只能说你太low
首先明明电脑上,就有清理垃圾和无用注册表的功能,只是我么缺少发现美的眼睛. 为什么不用360,腾讯全家桶. 那玩意固然香,而且真香,但是后台占用率太高,作为一个有洁癖的我,实在是不想看到自己右下角多一 ...
- ACM--[kuangbin带你飞]--专题1-23
专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 FliptilePOJ 1426 Find T ...
- CF1328B K-th Beautiful String
CF1328B K-th Beautiful String,然而CF今天却上不去了,这是洛谷的链接 题意 一个长度为\(n\)的字符串,有2个\(\texttt{b}\)和\(n-2\)个\(\tex ...