Submission #19724645


Source Code Expand

Copy
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
ll getSum(ll x)
{
    return x*(x+1)/2;
}
ll f(ll a,ll b,ll c,ll n)
{
    if(!n) return b/c;
    if(!a) return (n+1)*(b/c);
    if(a>=c||b>=c) return getSum(n)*(a/c)+(n+1)*(b/c)+f(a%c,b%c,c,n);
    return n*((a*n+b)/c)-f(c,c-b-1,a,(a*n+b)/c-1);
}
int main()
{
    int t;
    ll a,b,c,d;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
        ll k=(d-2)/(c-b);
        ll ans=f(c,a,d,k)-f(b,a-1,d,k);
        printf("%lld\n",k-ans);
    }
    return 0;
}

Submission Info

Submission Time
Task E - Simple Math 3
User whix
Language C++ (GCC 9.2.1)
Score 800
Code Size 593 Byte
Status AC
Exec Time 28 ms
Memory 3760 KB

Compile Error

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

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 800 / 800
Status
AC × 1
AC × 21
Set Name Test Cases
Sample example_00
All example_00, max_random_00, max_random_01, max_random_02, max_random_03, max_random_04, max_random_05, max_random_06, max_random_07, max_random_08, max_random_09, small_00, small_01, small_02, small_03, small_04, small_bc_00, small_bc_01, small_bc_02, small_bc_03, small_bc_04
Case Name Status Exec Time Memory
example_00 AC 7 ms 3656 KB
max_random_00 AC 16 ms 3668 KB
max_random_01 AC 19 ms 3512 KB
max_random_02 AC 16 ms 3516 KB
max_random_03 AC 28 ms 3668 KB
max_random_04 AC 16 ms 3760 KB
max_random_05 AC 17 ms 3652 KB
max_random_06 AC 16 ms 3648 KB
max_random_07 AC 16 ms 3528 KB
max_random_08 AC 19 ms 3692 KB
max_random_09 AC 18 ms 3652 KB
small_00 AC 13 ms 3648 KB
small_01 AC 11 ms 3608 KB
small_02 AC 13 ms 3652 KB
small_03 AC 16 ms 3532 KB
small_04 AC 12 ms 3748 KB
small_bc_00 AC 24 ms 3556 KB
small_bc_01 AC 23 ms 3532 KB
small_bc_02 AC 20 ms 3608 KB
small_bc_03 AC 25 ms 3656 KB
small_bc_04 AC 28 ms 3648 KB