Tuesday, May 16, 2017

uva problem solution 11934 - Magic Formula



problem link



Discussion: It is just a simple problem just evaluate the value of function inside loop and change the value of x with the increasing value of i.


try yourself before see the code.


#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long a,b,c,x,l,d,cnt,i,j,p,q,fun;
   while(cin>>a>>b>>c>>d>>l)
   {
   cnt=0;
      if(a==0&&b==0&&c==0&&d==0&&l==0)
      break;

      for(i=0;i<=l;i++)
      {
      x=i;
      fun=a*x*x+b*x+c;
         if(fun%d==0)
         cnt++;

      }
      cout <<cnt<<endl;

   }
   return 0;

}

No comments:

Post a Comment