Here you will find solutions of many problems on spoj. If you want solution of some problem which is not listed in blog or have doubt regarding any spoj problem (which i have solved) or any programming concept (data structure) you can mail me @ raj.nishant360@gmail.com

And my humble request to you all that don't copy the code only try to understand the logic and algorithm behind the code. I have started this because if you tried as hard as you can and still can't find any solution to the problem then you can refer to this.
You can read my answer how to start competitive programming CLICK HERE

Tuesday, April 15, 2014

INS14B-TRISQRS

TRISQRS

Given below code is for ins14b spoj or trisqrs spoj.
Here the area of largest triangle possible in a square is (N*N)/2;
So we have to count the total number of divisors of  (N*N)/2.
My algorithm is very time consuming if any one can suggest me more fast algorithm for finding total number of divisors of a number please comment or mail me @ :-> raj.nishant360@gmail.com .That will be very help full to me.

#include <bits/stdc++.h>
using namespace std;
int num[1000009]={0};
void pre()
{
 for(int i=2;i<=1000;i++)
 {
  if(!num[i])
  for(int j=i*i;j<=1000000;j+=i)
   if(!num[j])
    num[j]=i;
 }
}
int main()
{
 int t;
 pre();
 scanf("%d",&t);
 while(t--)
 {
  int n;
  scanf("%d",&n);
  if(n&1){
   printf("0\n");
   continue;}
  n*=n;
  n>>=1;
  cout<<n<<endl;
  map<int ,int >mp;
  map<int ,int >::iterator t;
  if(num[n]!= 0)
   while(n%num[n] == 0)
   {
    mp[num[n]]+=1;
    if(num[n] == 0)
     break;
    n/=num[n];
    if(num[n]==0)
     break;
   }
  mp[n]+=1;
  int result =1;
  for(t=mp.begin();t!=mp.end();t++)
   result *= (t->second + 1);
  printf("%d\n",result);
 }
 return 0;
}

No comments:

Post a Comment

Your comment is valuable to us