题目链接: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. [转]利用/*+Ordered*/提高查询性能

    [转]利用/*+Ordered*/提高查询性能 2009-02-06 10:46:27|  分类: Oracle |  标签: |字号大中小 订阅  消耗在准备利用Oracle执行计划机制提高查询性能 ...

  2. js常见事件

    1.onblur:(使用在表单元素中,当元素失去焦点的时候执行) 2.onchange:(使用在表单元素中,当某些东西改变是执行) 3.onclick:(鼠标点击一个元素时执行) 4.ondblcli ...

  3. c++ 重定位输出到DOS

    #define USE_WIN32_CONSOLE int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTST ...

  4. linux 安装Tesseract-OCR

    linux 安装Tesseract-OCR 准备工作:一.编译环境: 1. gcc gcc-c++ make(这个环境一般机器都具备,可以忽略) yum install gcc gcc-c++ mak ...

  5. eclipse查看.project .class隐藏文件

    fileter ->*.resource勾选:

  6. Subline Text默认设置文件Preferences.sublime-settings—Default详解

    Subline Text中,点击Preferences,选择Settings - Default 全部属性解析 // While you can edit this file, it's best t ...

  7. Understanding Memory Management(2)

    Understanding Memory Management Memory management is the process of allocating new objects and remov ...

  8. hadoop 原理: 浅析Hadoop文件格式

    Hadoop 作为MR 的开源实现,一直以动态运行解析文件格式并获得比MPP数据库快上几倍的装载速度为优势.不过,MPP数据库社区也一直批评Hadoop由于文件格式并非 为特定目的而建,因此序列化和反 ...

  9. 注意EntityFramework.extended中的坑

    EntityFramework.extended 的好处就不用多说了 详情:https://github.com/loresoft/EntityFramework.Extended 但是使用时还是要注 ...

  10. BZOJ2553: [BeiJing2011]禁忌

    2553: [BeiJing2011]禁忌 Time Limit: 20 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 203  Solved: ...