quadratic equation (余数)

AI权益加码!Claude Code、Cursor等20+工具免费用! 购周边限时加赠Coding Plan Lite,畅享主流AI工具!学习进阶更高效! 阅读详情

quadratic equation

Time Limit: 2000 ms Memory Limit: 131072 KiB
Problem Description

With given integers a,b,c, you are asked to judge whether the following statement is true: "For any x, if a+bx+c=0, then x is an integer."

Input

The first line contains only one integer T(1≤T≤2000), which indicates the number of test cases.
For each test case, there is only one line containing three integers a,b,c(−5≤a,b,c≤5).

Output

or each test case, output “YES” if the statement is true, or “NO” if not.

Sample Input
3
1 4 4
0 0 1
1 3 1
Sample Output
YES
YES
NO

1.这个题目就是要清楚,一个蕴含表达式只有前真后假的情况,才会使得整个表达式取得假值,就算前件为假,表达式也是真的。

2.要学会求解x为整数的时候,用取余的方法。

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;


int check(int a,int b,int c)
{
if(a==0)
{
if(b==0)
{
if(c==0)// 此时x可以取任何值不成立,可以取任意值,就可以说明可以取到非整数 
{
return 0;
}
return 1;//此时存在一个整数X
}
else if(c%b==0) return 1;//b*x=c;x=c/b;因为题目中要求x为整数,也就是说,(-c)%b==0
return 0;
}
int d=b*b-4*a*c;
int D=(int)sqrt(d);
if(d<0)  return 1;  //因为这是蕴含表达式,所以就算前件不成立,整个表达式确是真的 
    if(fabs(D - sqrt(d)) < 0.00000001)
    {
    if(((-1)*b-D)%(2*a)==0)
       if(((-1)*b+D)%(2*a)==0)
      return 1;
}
return 0;


}
int main()
{
int t;
int a,b,c;
cin>>t;
while(t--)
{
cin>>a>>b>>c;
if(check(a,b,c))
 cout<<"YES"<<endl;
else
 cout<<"NO"<<endl;
}
return 0;
}
Quadratic Equation(C++)的输出格式 Quadratic Equation题目正文输入输出样例代码知识总结 题目正文 求解方程ax2+bx+c=0的根。要求a b c由用户输入,并且可以为任意实数。 输入 输入只有一行,包括三个系数,之间用空格格开。 输出 输出只有一行,包括两个根,大根在前,小根在后,无需考虑特殊情况,保留小数点后两位。 样例 2.5 7.5 1.0 -0.14 -2.86 代码 代码. #include<stdio.h> #include<iostream> #include<iomanip&g 阅读详情

相关推荐

算法提高 Quadratic Equation

问题描述   求解方程ax2+bx+c=0的根。要求a, b, c由用户输入,并且可以为任意实数。   输入格式:输入只有一行,包括三个系数,之间用空格格开。   输出格式:输出只有一行,包括两个根,大根在前,小根在后,无需考虑特殊情况,保留小数点后两位。   输入输出样例 样例输入 2.5 7.5 1.0 样例输出 -0.14 -2.86

最有趣的编程 633

(code jam)Problem C. Numbers

Problem In this problem, you have to find the last three digits before the decimal point for the number (3 + √5)n. For example, when n = 5, (3 + √5)5 = 3935.73982... The answer is 935. For n = 2, (

无奈滴微笑 1017

Google Code Jam 2008 Round 1A C Numbers(矩阵快速幂+化简方程,好题)

Problem C.Numbers This contest is open for practice. You can try every problem as many times as you like, though we won't keep track of which problems you solve. Read theQuick-Start Guideto ge...

weixin_30563319的博客 176

quadratic equation

Think: PS :题目出自 “浪潮杯”山东省第八届ACM大学生程序设计竞赛题目意思 就是判断 当且仅当 x 为整数时, a * x * x + b * x + c = 0成立; 所以只要判断 a b c 三者对应的解即可; 一: a == 0 && b == 0 此时 若 c == 0 则 x 属于 R 所以不成立, 若 c != 0 则 无论 x 取何值

不积跬步,无以至千里 710

Quadratic equation

1

qq_66485519的博客 648

Java Quadratic Equation

问题描述 求解方程ax2+bx+c=0的根。要求a, b, c由用户输入,并且可以为任意实数。   输入格式:输入只有一行,包括三个系数,之间用空格格开。   输出格式:输出只有一行,包括两个根,大根在前,小根在后,无需考虑特殊情况,保留小数点后两位。   输入输出样例 样例输入 2.5 7.5 1.0 样例输出 -0.14 -2.86 代码: import java.util.Scanner; ...

a215012954的博客 783

Quadratic Equation

题目描述 求解方程ax2+bx+c=0的根。要求a, b, c由用户输入,并且可以为任意实数。 输入 输入只有一行,包括三个系数,之间用空格格开。 输出 输出只有一行,包括两个根,大根在前,小根在后,无需考虑特殊情况,保留小数点后两位。 样例输入 2.5 7.5 1.0 样例输出 -0.14 -2.86 #include<bits/stdc++.h> #include<c...

Allen的博客 475

HAUTOJ quadratic equation

问题 F: quadratic equation 时间限制: 2 秒  内存限制: 128 MB 提交: 268  解决: 42     题目描述 With given integers a,b,c, you are asked to judge whether the following statement is true:"For any x, if a⋅x2+b⋅x+c=0

什么样的小孩 的博客 449

Java实现 蓝桥杯VIP 算法提高 Quadratic Equation

算法提高 Quadratic Equation 时间限制:1.0s 内存限制:512.0MB 问题描述   求解方程ax2+bx+c=0的根。要求a, b, c由用户输入,并且可以为任意实数。   输入格式:输入只有一行,包括三个系数,之间用空格格开。   输出格式:输出只有一行,包括两个根,大根在前,小根在后,无需考虑特殊情况,保留小数点后两位。   输入输出样例 样例输入 2.5 7.5 ...

南 墙 1万+

Quadratic equation(二次剩余定理)

题目描述 Amy asks Mr. B problem B. Please help Mr. B to solve the following problem. Let p = 1000000007. Given two integers b and c, please find two integers x and y(0≤x≤y&l...

哇哈哈哈的博客 1858

quadratic equation(坑爹判断)

quadratic equationProblem DescriptionWith given integers a,b,c, you are asked to judge whether the following statement is true: "For any x, if a⋅+b⋅x+c=0, then x is an integer."InputThe first line con...

codeswarrior的博客 836

Quadratic equation(二次剩余,板子)

链接:https://ac.nowcoder.com/acm/contest/889/B 来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld 题目描述 Amy asks Mr. B problem B. Please help Mr. B to solve the followin...

ccsu_deer 594

牛客网 Quadratic equation【二次剩余】

思路:这道题考察到了二次剩余,不考虑取模 (x - y)^2 = (x + y) ^ 2 - 4xy = b^2 - 4c 考虑取模 (x - y)^2 mod p = b^2 - 4c mod p (同余) a是模p的二次剩余的充要条件为a^((p-1)/2) 同余 1 mod p #include <bits/stdc++.h> using namespace std; t...

独钓门前月 472

F——quadratic equation

quadratic equation Time Limit: 2000MS Memory Limit: 131072KB Submit Statistic Problem Description With given integers a,b,c, you are asked to judge whether the following statement is tru

SoyBean 386
上一篇: 搜索 C - Prime Ring Problem
下一篇: 3899 sum of power
SY_Pistachio
博客等级 码龄9年 74粉丝 272原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值