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