D_ROLL - Editorial

PROBLEM LINK:

Practice
Contest

Author: rocknot
Tester: root_rvl
Editorialist: rocknot

DIFFICULTY:

EASY

PREREQUISITES:

Permutations and combinations

PROBLEM:

Meena is playing snake and ladders with his friends and after a while they got bored and They decided to play guessing game where they had to roll the dice and guess its outcome. Meena is very bad at guessing and failed most of the time in guessing correct outcome. While casually thinking of this game he realized that rolling a dice is totally random and winning is just factor of luck. So he decided to modify this game such that probability of getting correct outcome will increase so that he can win with his friend. After a while he found a method he took two dice and calculated their average sum of all their possible outcomes.As he now has the average sum he can easily determine the outcome.for normal dice his friend will easily guess the outcome so Meena decided to take K, N sided dices. You need to determine the average sum for all possible outcomes.

Example

for N=3 & K= 2, of outcomes will be (1,1),(1,2),(1,3), (2,1),(2,2),(2,3), (3,1),(3,2),(3,3) so average sum will sum of all the pairs of outcomes divided by total no out comes (2.1)/9 + (3.2)/9 + (4.3)/9 + (5.2)/9 +(6.1)/9= 4 so the average sum will be 4.

EXPLANATION:

rolling dice is an independent event so if we roll multiple dice average sum of single dice and multiply it by total no of dice so it will be simply (K*(N*(N+1))/2)N =
K*(N+1)/2

SOLUTIONS:

Setter's Solution
#include <bits/stdc++.h>
using namespace std;
int main(){
    int T;
    cin>>T;
    while(T--){
        double N,K;
        cin>>N>>K;
        cout<<K*(N+1)/2<<endl;
    }
    return 0;
}