首页 技术 正文
技术 2022年11月15日
0 收藏 929 点赞 2,925 浏览 648 个字

算法提高 解二元一次方程组

时间限制:1.0s 内存限制:256.0MB

问题描述

  给定一个二元一次方程组,形如:

  a * x + b * y = c;

  d * x + e * y = f;

  x,y代表未知数,a, b, c, d, e, f为参数。

  求解x,y

输入格式

  输入包含六个整数: a, b, c, d, e, f;

输出格式

  输出为方程组的解,两个整数x, y。

样例输入

例:

3 7 41 2 1 9

样例输出

例:

2 5

数据规模和约定

  0 <= a, b, c, d, e, f <= 2147483647

import java.io.IOException;
import java.util.Scanner;public class 解二元一次方程组 {
public static void main(String args[]) {
Scanner sc =new Scanner(System.in);int a, b, c, d, e, f;
a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();
d = sc.nextInt();
e = sc.nextInt();
f = sc.nextInt();int lcm = a * d / gcd(a, d);// 最小公倍数
int a1 = lcm / a;
int d1 = lcm / d;
int y = (c * a1 - f * d1) / (b * a1 - e * d1);
int x = (c - b * y) / a;
System.out.println(x + " " + y);}private static int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,493
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,295