ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1063. Domino Puzzle

<P><P><P> What wrong with this solution??? [6] // Problem 1063. Domino Puzzle 16 Apr 2003 14:15
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

short a[10000];
short sets[10000];
short p[10000];

int main()
{
  long i,n;
//  freopen("input.txt","rt",stdin);
//  freopen("output.txt","wt",stdout);

  while (scanf("%ld",&n)==1)
  {
  if (n==1) { printf("1\n"); continue; }
    long k,j,sum;
    sum=0;

    memset(a,0,sizeof(a));
    memset(sets,0,sizeof(sets));

    for (i=0; i<n; i++)
    {
      scanf("%ld",&k);
      for(j=2; j<=k; j++) a[j]--;
      sets[k]++;
      sum+=k;
    }
    for(j=2; j<=sum; j++) a[j]++;
    for(i=1; i<=sum; i++)
      for(j=2; j<=sets[i]; j++) a[j]--;

    memset(p,0,sizeof(p));
    unsigned long result=1;
    for(i=2; i<=sum; i++)
    if(!p[i])
    {
      j=i+i;
      while (j<=sum)
    { p[j]=1;
      k=j;
      while(k%i==0) {
        k/=i;
        a[i]+=a[j];
      }
      j+=i;
    }

      for(j=a[i]; j>=1; j--) result*=i;
    }
    printf("%lu\n",result);
  }

  exit(0);
  return 0;
}
Crazy Lemming Re: What wrong with this solution??? [1] // Problem 1063. Domino Puzzle 18 Apr 2003 14:30
You've made a terrible mistake. What does it mean "sum+=k"? IS NOT A
PASCAL STYLE! Use "sum=sum+k"!
RoskaTa Re: What wrong with this solution??? // Problem 1063. Domino Puzzle 6 Jun 2008 13:01
Crazy Lemming you are not very informed with C and C++!
It can be done in the way you say and in the way he made it!
In c++ and in C(as i suppose) sum+=k adds k to sum!
In pascal can be different but in C or C++ it isn't!

Edited by author 06.06.2008 13:04

Edited by author 06.06.2008 13:04