【随机大法好】AtCoder Beginner Contest 133 C - Remainder Minimization 2019

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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值