Subset Sum

QUESTION

Peter is very weak in mathematics. His father gave him a problem and left to work. He is a lazy lad and he wants you to find the solution.\n\nGiven a set A which contains elements ranging from 1 to N.Find the sum of the elements in all possible subsets of the given set.\n\nInput Format:\n\nT, the number of test cases. Following T lines contain N, number of elements in set.\n\nOutput Format:\n\nT lines indicating the subset sum. print the answer modulo (10^9+7).\n\nConstraints: \n\n1<=T<=1000 \n1<=N<=2000.

ANSWER

#include<stdio.h>
int main()
{
   int t;
   scanf("%d",&t);
   while(t--)
  {
     int n,i;
     scanf("%d",&n);
     long long int ans=1;
     for(i=0;i<n-1;i++)
        ans=ans<<1;
     ans=ans*(n*(n+1))/2;
     printf("%lld\n",ans);
   }
   return 0;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.