当前位置:   article > 正文

Codeforces Round #704 (Div. 2)A_codeforces 704 div2

codeforces 704 div2

A. Three swimmers
time limit per test1 second
memory limit per test512 megabytes
inputstandard input
outputstandard output
Three swimmers decided to organize a party in the swimming pool! At noon, they started to swim from the left side of the pool.

It takes the first swimmer exactly a minutes to swim across the entire pool and come back, exactly b minutes for the second swimmer and c minutes for the third. Hence, the first swimmer will be on the left side of the pool after 0, a, 2a, 3a, … minutes after the start time, the second one will be at 0, b, 2b, 3b, … minutes, and the third one will be on the left side of the pool after 0, c, 2c, 3c, … minutes.

You came to the left side of the pool exactly p minutes after they started swimming. Determine how long you have to wait before one of the swimmers arrives at the left side of the pool.

Input
The first line of the input contains a single integer t (1≤t≤1000) — the number of test cases. Next t lines contains test case descriptions, one per line.

Each line contains four integers p, a, b and c (1≤p,a,b,c≤1018), time in minutes after the start, when you came to the pool and times in minutes it take the swimmers to cross the entire pool and come back.

Output
For each test case, output one integer — how long you have to wait (in minutes) before one of the swimmers arrives at the left side of the pool.
先算出每个人在开始等待时还有几分钟到达岸边,再分别减去得出最小值答案,需要再判断一下答案等于0的情况


#include<bits/stdc++.h>
using namespace std;
 #define ll long long
 const int mod = 1e9 + 7;
 
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		ll p,a,b,c;
		scanf("%lld%lld%lld%lld",&p,&a,&b,&c);
		ll ans1 = p%a,ans2 = p%b,ans3 = p%c;
		ll ans = min(a-ans1,min(b-ans2,c-ans3));
		if(min(p%a,min(p%b,p%c)) == 0)
		ans = 0;
		printf("%lld\n",ans);
	}
	
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/54898
推荐阅读
相关标签
  

闽ICP备14008679号