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 1055. Combinations

Need help. Solution too slow. Code included
Posted by Valentin Baltadjiev 19 Feb 2009 01:13
Can someone help me? With this source it is working for 2.031. How can I improve it?
#include<iostream>
using namespace std;
long long nod(long long a,int b){
 while(a!=0&&b!=0){
  if(a>b) a%=b;
  else b%=a;
 }
  return a+b;
 }
int main()

{
 long long  last[50000];
int n,k,i,j,l,br=0;
 cin>>n>>k;
 last[0]=1;
 for(i=0;i<=n;i++)
 {
  last[i]=1;
  for(j=i-1;j>0;j--)last[j]=last[j]+last[j-1];
 }
//cout<<last[k]<<endl;
 for(l=2;l<last[k];l++){
  if(nod(last[k],l)!=1) br++;
  while(last[k]%l==0)last[k]/=l;

 }
 cout<<br<<endl;
//system("pause");
 return 0;
}