https://atcoder.jp/contests/abc133/tasks/abc133_c
C - Remainder Minimization 2019
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 300 points
Problem Statement
You are given two non-negative integers L and R. We will choose two integers i and j such that L≤i<j≤R. Find the minimum possible value of (i×j) mod 2019.
Constraints
- All values in input are integers.
- 0≤L<R≤2×1e9
Input
Input is given from Standard Input in the following format:
L R
Output
Print the minimum possible value of (i×j) mod 2019 when i and j are chosen under the given condition.
Sample Input 1 Copy
Copy
2020 2040
Sample Output 1 Copy
Copy
2
When (i,j)=(2020,2021), (i×j) mod 2019=2
Sample Input 2 Copy
Copy
4 5
Sample Output 2 Copy
Copy
20
We have only one choice: (i,j)=(4,5)
题意:给你两个数,L,R,让你在这段区间内选两个数i<j,问你i*j%2019最小是几
解析:想了好久想不出怎么办,觉得很容易就可以更新最小值,就尝试着rand()了一发过了,不确定是不是正解
/*
由于rand产生的随机数从0到rand_max,而rand_max是一个很大的数,那么如何产生从X~Y的数呢?
从X到Y,有Y-X+1个数,所以要产生从X到Y的数,只需要这样写:
k=rand()%(Y−X+1)+X;
*/
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
srand((unsigned)time(NULL));
ll X,Y;
cin>>X>>Y;
ll ans=2019;
for(int i=1;i<=10000000;i++)
{
ll a=rand()%(Y-X)+X; //生成[x,y-1]的数
ll b=rand()%(Y-a)+a+1; //生成[a+1,y]的数
ll num=a*b%2019;
ans=min(ans,num);
}
cout<<ans<<endl;
return 0;
}