题目链接: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 数论的更多相关文章

  1. Ural 2003: Simple Magic(数论&思维)

    Do you think that magic is simple? That some hand-waving and muttering incomprehensible blubber is e ...

  2. Codeforces 919E Congruence Equation ( 数论 && 费马小定理 )

    题意 : 给出数 x (1 ≤ x ≤ 10^12 ),要求求出所有满足 1 ≤ n ≤ x 的 n 有多少个是满足 n*a^n  = b ( mod p ) 分析 : 首先 x 的范围太大了,所以使 ...

  3. Hough Transform

    Hough Transform Introduction: The Hough transform is an algorithm that will take a collection of poi ...

  4. Applying Eigenvalues to the Fibonacci Problem

    http://scottsievert.github.io/blog/2015/01/31/the-mysterious-eigenvalue/ The Fibonacci problem is a ...

  5. Data Visualization – Banking Case Study Example (Part 1-6)

    python信用评分卡(附代码,博主录制) https://study.163.com/course/introduction.htm?courseId=1005214003&utm_camp ...

  6. Realtime Rendering 5

    [Real Time Rendering 5] 1.In radiometry, the function that is used to describe how a surface reflect ...

  7. (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 ...

  8. 【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 ...

  9. Neural Networks and Deep Learning

    Neural Networks and Deep Learning This is the first course of the deep learning specialization at Co ...

随机推荐

  1. 软件测试 -- 测试人员和QA的区别

    软件测试人员的职责是尽可能早的找出软件缺陷,确保得以修复. 而质量保证人员(QA)主要职责是创建或者制定标准和方法,提高促进软件开发能力和减少软件缺陷. 测试人员的主要工作是测试,质量保证人员日常工作 ...

  2. [Gauss]POJ1222 EXTENDED LIGHTS OUT

    题意:给一个5*6的矩阵 1代表该位置的灯亮着, 0代表该位置的灯没亮 按某个位置的开关,可以同时改变 该位置 以及 该位置上方.下方.左方.右方, 共五个位置的灯的开.关(1->0, 0-&g ...

  3. Android ListView(Selector 颜色)

    listview_color.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout ...

  4. [jobdu]从尾到头打印链表

    九度确实烂啊,用cin就超时,必须要scanf.唯一可说的就是pplast和递归打印.也可以用stack,其实和递归一样的空间复杂度. #include<stdio.h> using na ...

  5. Android 发送HTTP GET POST 请求以及通过 MultipartEntityBuilder 上传文件

    折腾了好几天的 HTTP 终于搞定了,经测试正常,不过是初步用例测试用的,因为后面还要修改先把当前版本保存在博客里吧. 其中POST因为涉及多段上传需要导入两个包文件,我用的是最新的 httpmine ...

  6. JAVA线程优化

    Java并发编程:线程池的使用 在前面的文章中,我们使用线程的时候就去创建一个线程,这样实现起来非常简便,但是就会有一个问题: 如果并发的线程数量很多,并且每个线程都是执行一个时间很短的任务就结束了, ...

  7. bzoj2738

    感人肺腑pascal过不去系列,跪求开O2先不说这个了,学完cdq分治之后又顺手学了一下整体二分感觉这两个东西很多相似的地方,干脆都叫cdq分治好了二分解决k小就是设当前二分的答案为m,把x<= ...

  8. bzoj3514

    好题+数据结构神题+感人肺腑pascal被卡系列,我下面的代码几乎写到最优可怎耐bzoj上pascal开的是O1,c++开的是O2,这怎么可能跑得过!!!还是说说方法吧,这是一道算贡献的好题,因为我们 ...

  9. Ajax的同步和异步

    在实际编程过程中,涉及到很多同步和异步的问题,例如: $("#btnTJ").bind("click", function () { //第一条语句 $.pos ...

  10. phpMyAdmin 'import.php'跨站脚本漏洞

    漏洞版本: phpMyAdmin phpMyAdmin 3.4.9 phpMyAdmin phpMyAdmin 3.4.8 phpMyAdmin phpMyAdmin 3.4.6 phpMyAdmin ...