Created
December 20, 2015 07:56
-
-
Save kp96/f8af33f36cc8ee0cf64b to your computer and use it in GitHub Desktop.
Spoj solution to BALLSUM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* @Author: Krishna | |
* @Date: 2015-12-20 04:38:55 | |
* @Last Modified by: Krishna | |
* @Last Modified time: 2015-12-20 06:44:20 | |
*/ | |
#include <iostream> | |
#include <cstdio> | |
#include <algorithm> | |
#include <stack> | |
#include <queue> | |
#include <cmath> | |
#include <vector> | |
#include <set> | |
#include <omp.h> | |
#include <cstring> | |
#include <map> | |
#define ull unsigned long long | |
#define ll long long | |
#define sci(i) scanf("%d",&i) | |
#define scl(i) scanf("%ld",&i) | |
#define scll(i) scanf("%lld",&i) | |
#define rep(i,n) for(int i = 0; i < n; ++i) | |
#define loop(i,x,y) for(int i = x; i < y; ++i) | |
using namespace std; | |
typedef pair<int,int> pii; | |
typedef map<int,int> mii; | |
typedef map<int,int>::iterator miit; | |
int max (int a, int b) { return a > b ? a : b;} | |
int min (int a, int b) { return a < b ? a : b;} | |
ll gcd(ll a, ll b){ return (b==0)? a : gcd(b, a%b);} | |
int main() { | |
ull n, k; | |
while(true) { | |
scll(n); | |
scll(k); | |
if(n == -1 && k == -1) break; | |
else if(k <= 2) cout << 0 << endl; | |
else { | |
ll nn = (k-1)/2; | |
ll p = nn*k - nn*(nn+1); | |
//cout << p << endl; | |
ll q; | |
if(n & 1) | |
q = ((n-1)/2) * n; | |
else | |
q = (n/2) * (n-1); | |
//cout << p << " " << q << endl; | |
while(true) { | |
ll g = gcd(p,q); | |
if(g == 1) break; | |
//cout <<"gcd:"<< g << endl; | |
p /= g; | |
q /= g; | |
if(p == 1 || q == 1) break; | |
} | |
if(q == 1) printf("%lld\n", p); | |
printf("%lld/%lld\n",p,q); | |
} | |
} | |
//system("pause"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment