zoj Simple Equation 数论
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5176
AX+BY = XY => (X-B)*(Y-A)= A*B
对A*B因式分解,这里不要乘起来,分A,B因式分解
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<sstream>
#include<queue> #define MAXN 105000
#define PI acos(-1.0)
#define LL long long
#define REP(i,n) for(int i=0; i<n; i++)
#define FOR(i,s,t) for(int i=s; i<=t; i++)
#define show(x) { cerr<<">>>"<<#x<<" = "<<x<<endl; }
#define showtwo(x,y) { cerr<<">>>"<<#x<<"="<<x<<" "<<#y<<" = "<<y<<endl; }
using namespace std; LL A,B,X,Y,ansX,ansY,M;
int prime[MAXN],cnt; //生成质数表
LL sum_AB;
struct Factor
{
int p,k; //p^k;
}a[];
int pv; void get_prime()
{
bool flag[MAXN];
memset(flag,,sizeof(flag));
cnt = ; for(int i=; i<MAXN; i++)
{
if(!flag[i])
{
prime[cnt++] = i;
for(int j=i+i; j<MAXN; j+=i) flag[j] = true;
}
}
} void factor_analysis(int c,int d)
{
pv = ;
for(int i=; i<cnt && (c||d); i++)
{
if(c%prime[i] == || d%prime[i] == )
{
a[pv].p = prime[i];
a[pv].k = ;
while(c % prime[i] == ) a[pv].k++,c /= prime[i];
while(d % prime[i] == ) a[pv].k++,d /= prime[i];
pv++;
}
}
if(c != ) a[pv].p = c,a[pv].k = ,pv++;
if(d != ) a[pv].p = d,a[pv].k = ,pv++;
} void dfs(int pos,long long mul)
{
if(pos == pv && sum_AB % mul == )
{
X = mul + B;
Y = sum_AB / mul + A;
if(X >= M && (ansX+ansY > X+Y || (ansX+ansY == X+Y && ansX > X)))
ansX = X, ansY = Y;
return;
}
long long accu = ;
for(int i=; i<=a[pos].k; i++)
{
dfs(pos+,mul*accu);
accu *= a[pos].p;
}
} int main()
{
//freopen("E:\\acm\\input.txt","r",stdin);
get_prime();
while(scanf("%lld %lld %lld",&A,&B,&M) == )
{
sum_AB = A*B;
factor_analysis(A,B);
ansX = 1e18+, ansY = ;
dfs(,); if(ansX == 1e18+ ) printf("No answer\n");
else printf("%lld %lld\n",ansX,ansY);
}
}
zoj Simple Equation 数论的更多相关文章
- Ural 2003: Simple Magic(数论&思维)
Do you think that magic is simple? That some hand-waving and muttering incomprehensible blubber is e ...
- Codeforces 919E Congruence Equation ( 数论 && 费马小定理 )
题意 : 给出数 x (1 ≤ x ≤ 10^12 ),要求求出所有满足 1 ≤ n ≤ x 的 n 有多少个是满足 n*a^n = b ( mod p ) 分析 : 首先 x 的范围太大了,所以使 ...
- Hough Transform
Hough Transform Introduction: The Hough transform is an algorithm that will take a collection of poi ...
- Applying Eigenvalues to the Fibonacci Problem
http://scottsievert.github.io/blog/2015/01/31/the-mysterious-eigenvalue/ The Fibonacci problem is a ...
- Data Visualization – Banking Case Study Example (Part 1-6)
python信用评分卡(附代码,博主录制) https://study.163.com/course/introduction.htm?courseId=1005214003&utm_camp ...
- Realtime Rendering 5
[Real Time Rendering 5] 1.In radiometry, the function that is used to describe how a surface reflect ...
- (9)How to take a picture of a black hole
https://www.ted.com/talks/katie_bouman_what_does_a_black_hole_look_like/transcript 00:13In the movie ...
- 【Machine Learning is Fun!】1.The world’s easiest introduction to Machine Learning
Bigger update: The content of this article is now available as a full-length video course that walks ...
- Neural Networks and Deep Learning
Neural Networks and Deep Learning This is the first course of the deep learning specialization at Co ...
随机推荐
- ASP.NET MVC Spring.NET 整合
请注明转载地址:http://www.cnblogs.com/arhat 在整合这三个技术之前,首先得说明一下整合的步骤,俗话说汗要一口一口吃,事要一件一件做.同理这个三个技术也是.那么在整合之前,需 ...
- mongodb Install the MongoDB service
在用到mongodb时,首先要运行mongod.exe以启动mongo,这样就会出现命令框( command prompt),为了避免出现这种情况.要以服务的形式来启动mongo,这样就不会出现命令框 ...
- location.hash 详解
前年9月twitter改版. 一个显著变化,就是URL加入了"#!"符号.比如,改版前的用户主页网址为 http://twitter.com/username 改版后,就变成了 h ...
- public void Delete(List EntityList) where T : class, new()类型参数约束
查找后发现这是类型参数约束,.NET支持的类型参数约束有以下五种: where T : struct | T必须是一个结构类型 where T : class T必须是一个类(class)类型 whe ...
- POJ 3274 Gold Balanced Lineup(哈希)
http://poj.org/problem?id=3274 题意 :农夫约翰的n(1 <= N <= 100000)头奶牛,有很多相同之处,约翰已经将每一头奶牛的不同之处,归纳成了K种特 ...
- Cocos2d-x内存自动释放机制--透彻篇
首先在架构里面需要明白,如果使用new创建对象的话,我们需要自己释放内存,如果直接用引擎提供的警静态方法,我们可以不做内存管理,引擎自动处理,因为引擎背后有一个自动释放池.通过查看源码可以知道,每个静 ...
- 驱动开发 - WDK 调试及 SVN 环境搭建
由于从公司辞职了,所以以前在公司里搭建的驱动开发环境也就 Game Over 了, 同样由于那环境是很久以前搭建的,自己也有很多记不清楚的地方了, 而且其中还是有很多需要注意的地方的,所以在这里顺便做 ...
- Android 发送HTTP GET POST 请求以及通过 MultipartEntityBuilder 上传文件
折腾了好几天的 HTTP 终于搞定了,经测试正常,不过是初步用例测试用的,因为后面还要修改先把当前版本保存在博客里吧. 其中POST因为涉及多段上传需要导入两个包文件,我用的是最新的 httpmine ...
- Android 开发绕不过的坑:你的 Bitmap 究竟占多大内存?
0.写在前面 本文涉及到屏幕密度的讨论,这里先要搞清楚 DisplayMetrics 的两个变量,摘录官方文档的解释: density:The logical density of the displ ...
- ArcGIS Engine Style文件操作
对于一个GISer来说,地图,符号这些都应该有着比别人更深刻的理解和认识,作为平台软件都会提供一套自己的符号库,符号库里面根据类别和种类进行区分,因为点,线,面的自然存在和固有属性是不肯能让你用面状符 ...