Sort by

recency

|

52 Discussions

|

  • + 0 comments

    //c++ code

    include

    using namespace std;

    define endl '\n'

    define ig cin.ignore()

    define GET_FASTER ios_base::sync_with_stdio(false); cin.tie(NULL)

    typedef long long int ll; const ll mx= LLONG_MAX; const ll mn= LLONG_MIN; const ll MOD= 1e9+7; bool descending_order(int x, int y){return x>y;}

    long long nth_term(long long n){ return (n+(n*n))/2; }

    int main(){

    GET_FASTER;
    
    int t;
    cin>> t;
    
    while(t--){
        long long n,m;
        cin>> n>> m;
    
        long long rem= n %m;
        long long div= n/m;
        long long tem= m-1;
    
        long long result;
    
        result = ((nth_term(tem)*div)+ nth_term(rem));
    
        cout<< result<< endl;
    
    }
    
    
    return 0;
    

    }

  • + 0 comments

    Power-efficient - Integrated GPUs consume less power than dedicated GPUs, which makes them ideal for use in laptops and other mobile devices. https://upgpu.com/best-gpu-for-i5-9400f/

  • + 0 comments

    Gauss's summation implemented in Python.

    def solve(n, m):
        return ((m-1)*m//2)*(n//m)+(n%m)*(n%m+1)//2
    

    Explanation: Gauss's formula for summation states that the sum from 1 to N for any natural number, N, can be calculated arithmetically:

    The problem statement implies an approach where one would loop from 1 up to n, taking mod m at each step.
    However, with some out-of-the-box thinking, by applying the mod m ahead of time, you will see that in fact we are summing from 1 to m-1 over and over.
    The number of times we take this sum is equal to

    This means we can apply Gauss's formula to sum 1 to m-1:
    to get this preliminary value, and multiply the result by num_loops.
    If m divides n, this will be the result to return.
    However, if a remainder exists from the previous division, then there are a few more integers to add to the total. Simply apply Gauss's formula one more time,
    and add this to our total to be returned.

  • + 0 comments

    how to run out of memory: it supposed to work, while the n array is small XD

    def solve(n, m):
        tot = 0
        for num in range(1,n+1):
            tot += num%m
        return tot
    
  • + 0 comments

    C# function prototype provided won't work. Should be long not int.