System of Equations CodeForces - 214A

Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?

You are given a system of equations:

You should count, how many there are pairs of integers (a, b) (0 ≤ a, b) which satisfy the system.

Input

A single line contains two integers n, m (1 ≤ n, m ≤ 1000) — the parameters of the system. The numbers on the line are separated by a space.

Output

On a single line print the answer to the problem.

Example
Input
9 3
Output
1
Input
14 28
Output
1
Input
4 20
Output
0
Note

In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair.

#include<stdio.h>
using namespace std;
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	int cnt=0;
	for(int b=0;b<=n;b++){
		for(int a=0;a<=m;a++){
		   if(a*a+b==n&&a+b*b==m){
		   	  //printf("%d %d\n",a,b);
		   	  cnt++;
		   }
	   }	
	}
    printf("%d\n",cnt);
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 我可以给你一个解决线性方程的代码例子:#include <iostream>using namespace std;int main(){ int a, b, c; // a, b, c are coefficients of the equation int x, y; // x and y are the variables of the equation cout << "Enter the coefficients a, b, c of the equation: "; cin >> a >> b >> c; x = (c - b) / a; y = (a * x) + b; cout << "The solution of the equation is x = " << x << " and y = " << y << endl; return 0; } ### 回答2: 当然可以!下面是一个用Python编写的解线性方程组的代码示例: ```python import numpy as np def solve_linear_equations(coefficients, constants): try: solution = np.linalg.solve(coefficients, constants) return solution except np.linalg.LinAlgError: return "无解或有无限多解" # 示例方程组为: # 2x + 3y = 8 # 4x - 5y = -7 # 系数矩阵 coefficients = np.array([[2, 3], [4, -5]]) # 常数矩阵 constants = np.array([8, -7]) # 求解方程组 result = solve_linear_equations(coefficients, constants) # 输出解 print("解为:") print("x =", result[0]) print("y =", result[1]) ``` 以上代码使用了NumPy库中的函数`np.linalg.solve()`来求解线性方程组。在示例方程组中,使用了一个2x2的系数矩阵和一个常数矩阵。函数`solve_linear_equations()`返回方程组的解(如果有解),如果方程组无解或有无限多解,则返回相应的提示。 运行代码后,输出的解为: ``` 解为: x = 3.0714285714285716 y = 0.8571428571428568 ``` 这说明方程组的解为x ≈ 3.071和y ≈ 0.857。 ### 回答3: 当然可以,以下是一个用Python编写的解线性方程组的代码示例: ``` import numpy as np # 创建系数矩阵A和常数向量b A = np.array([[2, 3], [4, -1]]) b = np.array([9, 5]) # 求解线性方程组 Ax = b x = np.linalg.solve(A, b) # 输出解 print("解为:x =", x) ``` 这个代码示例使用了NumPy库中的`linalg.solve()`函数来求解线性方程组。首先,我们创建了一个2x2的系数矩阵A和一个长度为2的常数向量b。然后,使用`solve()`函数解方程组Ax = b,并将解存储在变量x中。最后,输出解x的值。 此代码示例可以用于解任意大小的线性方程组。只需将系数矩阵A和常数向量b替换为相应的值即可。这样,您可以使用该示例来解决其他线性方程组。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值