Submission #35610790


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int T; ll a,b,ans;
void solve();

int main()
{
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lld%lld",&a,&b);
        solve();
        printf("%lld\n",ans);
    }
}

void solve()
{
    ans=0x3f3f3f3f;
    ll m=b-1,l=1,r=1;
    while(r<=m)
    {
        r=m/(m/l); ll k=l;
        ll q=m/l;
        ans=min(ans,k*a+(k+1ll)*max(0ll,q-a+1ll)-b);
        l=r+1; r=l;
    }
    ll k=m+1,q=0;
    ans=min(ans,k*a+(k+1ll)*max(0ll,q-a+1ll)-b);
}

Submission Info

Submission Time
Task B - Make Divisible
User cjh_hhz
Language C++ (GCC 9.2.1)
Score 500
Code Size 547 Byte
Status AC
Exec Time 121 ms
Memory 3760 KiB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:10:10: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   10 |     scanf("%d",&T);
      |     ~~~~~^~~~~~~~~
./Main.cpp:13:14: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   13 |         scanf("%lld%lld",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 1
AC × 24
Set Name Test Cases
Sample 00-sample-001.txt
All 00-sample-001.txt, 01-random-001.txt, 01-random-002.txt, 01-random-003.txt, 01-random-004.txt, 01-random-005.txt, 01-random-006.txt, 01-random-007.txt, 01-random-008.txt, 01-random-009.txt, 01-random-010.txt, 01-random-011.txt, 01-random-012.txt, 01-random-013.txt, 01-random-014.txt, 01-random-015.txt, 02-random-001.txt, 02-random-002.txt, 02-random-003.txt, 02-random-004.txt, 02-random-005.txt, 03-test-001.txt, 03-test-002.txt, 03-test-003.txt
Case Name Status Exec Time Memory
00-sample-001.txt AC 11 ms 3568 KiB
01-random-001.txt AC 106 ms 3680 KiB
01-random-002.txt AC 110 ms 3676 KiB
01-random-003.txt AC 113 ms 3732 KiB
01-random-004.txt AC 116 ms 3656 KiB
01-random-005.txt AC 114 ms 3536 KiB
01-random-006.txt AC 107 ms 3648 KiB
01-random-007.txt AC 107 ms 3688 KiB
01-random-008.txt AC 112 ms 3656 KiB
01-random-009.txt AC 120 ms 3652 KiB
01-random-010.txt AC 110 ms 3700 KiB
01-random-011.txt AC 112 ms 3648 KiB
01-random-012.txt AC 109 ms 3684 KiB
01-random-013.txt AC 105 ms 3556 KiB
01-random-014.txt AC 112 ms 3544 KiB
01-random-015.txt AC 110 ms 3540 KiB
02-random-001.txt AC 118 ms 3556 KiB
02-random-002.txt AC 121 ms 3680 KiB
02-random-003.txt AC 118 ms 3676 KiB
02-random-004.txt AC 113 ms 3696 KiB
02-random-005.txt AC 118 ms 3760 KiB
03-test-001.txt AC 110 ms 3760 KiB
03-test-002.txt AC 4 ms 3688 KiB
03-test-003.txt AC 2 ms 3540 KiB