福大程序在线评测系统 Problem 1992 An Easy Problem 怎么解?

福大程序在线评测系统 Problem 1992 An Easy Problem 怎么解?
In mathematics, “MOD” operation is common. C = A (MOD B), which means that the
remainder of A after divided by B is equal to that of C. It’s an easy problem to
test whether A and C satisfy the condition above. But what you are expected to
is not so easy! You will be given A and C and to find the number of B who
satisfies the condition (equation) above, you could assume that A is not equal
to C in this problem.
输入
A=9,C=3
为什么结果是B=4
问题网址链接:http://acm.fzu.edu.cn/problem.php?pid=1992
lxc147 1年前 已收到1个回答 举报

砸你一头大疙瘩 春芽

共回答了17个问题采纳率:94.1% 举报

解法也很简单,因为模b余数相同,则可以设a = k1 * b + d,c = k2 * b + d a-c = (k1-k2)*b; 所以b是(a-c)的一个因数,答案就是(a-c)的因子数;
#include
#include
#include
using namespace std;
int main()
{
int a,c,total,t,tmp,cs = 0;
scanf("%d",&t);
while( t-- )
{
total = 0;
scanf("%d%d",&a,&c);
tmp = a > c a-c :c - a;
for(int i=1;i*i

1年前

3
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 16 q. 0.022 s. - webmaster@yulucn.com