Hackerrank Ad Infinitum - Math Programming Contest June'14 - Easy Sum editorial: https://www.hackerrank.com/contests/infinitum-jun14/challenges/easy-sum/editorial
Hackerrank Ad Infinitum - Math Programming Contest June'14 - Easy Sum solution:
#include <iostream> #include <cstdio> using namespace std; int main() { long long int t, n, m, s, c; scanf("%lld", &t); while(t--) { scanf("%lld%lld", &n, &m); s=c=0; s=m*(m-1)/2; c=s*(n/m); s=n%m; c+=s*(s+1)/2; printf("%lld\n", c); } return 0; }
note: use long long int. i used int and got 10 pts during the contest, after contest i changed it to long long int and got AC with 20 pts :(
No comments:
Post a Comment