Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- int main()
- {
- ll t=1,x,a,b,c,d,e,f,i,j,k,l,m,n,o,sum;
- while(scanf("%lld",&x))
- {
- sum=0;
- if(x==0) return 0;
- for(i=0;i<x;i++)
- {
- scanf("%lld",&b);
- sum+=b;
- }
- printf("Case %lld:\n",t++);
- if(abs(sum)%x==0)
- {
- if(sum<0) printf("- ");
- printf("%lld\n",abs(sum)/x);
- }
- else
- {
- if(abs(sum)%x!=0 && abs(sum)/x>=1)
- {
- c=x;
- d=abs(sum);
- e=__gcd(c,d);
- c=c/e;
- d=d/e;
- if(sum<0)
- {
- printf(" %lld\n",d%c);
- printf("- %lld-\n",d/c);
- printf(" %lld\n",c);
- }
- else if(sum>0)
- {
- printf(" %lld\n",d%c);
- printf("%lld-\n",d/c);
- printf(" %lld\n",c);
- }
- }
- else
- {
- c=x;
- d=abs(sum);
- e=__gcd(c,d);
- c=c/e;
- d=d/e;
- if(sum<0)
- {
- printf(" %lld\n",d);
- printf("- -\n");
- printf(" %lld\n",c);
- }
- else if(sum>0)
- {
- printf("%lld\n",d);
- printf("%-\n");
- printf("%lld\n",c);
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement