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 ...
随机推荐
- makefile的简单写法
makefile 使用方法: vi 一个Makefile文件 CC = g++ // 指的是用什么编译器RM = rm -rf // 定义一个删除的指令(变量)CFLAGS = -c -Wal ...
- 批量将MP4 转换为 MP3
0 需要先下载VLC 软件 1 win+R 运行 "CMD" 2 CD mp4目录 3 复制 并运行下面代码 for %%a in (*.mp4) do "C:\Prog ...
- Codeforces Round #359 div2
Problem_A(CodeForces 686A): 题意: \[ 有n个输入, +\space d_i代表冰淇淋数目增加d_i个, -\space d_i表示某个孩纸需要d_i个, 如果你现在手里 ...
- spring的主要特性
一.简化java开发.为了降低java开发的复杂性,Spring采取了以下4种关键策略: 1.基于POJO的轻量级和最小侵入性编程. 2.通过依赖注入和面向接口实现松耦合. 3.基于切面和惯例进行声式 ...
- 20 个最棒的 jQuery Tab 插件
jQuery Tab 常用来做网页上的选项设置界面和导航,本文向你推荐最棒的 20 个 jQuery Tab 插件.Enjoy !! 1. Slider Tabs SliderTabs 是一个可定制的 ...
- python join字符连接函数的使用方法
就是把一个list中所有的串按照你定义的分隔符连接起来,比如: >>> import string >>> >>> >>> li ...
- range([start], stop[, step]):产生一个序列,默认从0开始
range([start], stop[, step]):产生一个序列,默认从0开始 >>> l = range(10) >>> l [0, 1, 2, 3, 4, ...
- 递归解析XML
package com.app.test; import java.io.InputStream; import java.util.List; import org.dom4j.Attribute; ...
- 1012: [JSOI2008]最大数maxnumber
单点更新,区间求最大值的题: 可以使用树状数组和线段树: #include<cstdio> #include<cstring> #include<algorithm> ...
- iOS,Android网络抓包教程之tcpdump
现在的移动端应用几乎都会通过网络请求来和服务器交互,通过抓包来诊断和网络相关的bug是程序员的重要技能之一.抓包的手段有很多:针对http和https可以使用Charles设置代理来做,对于更广泛的协 ...