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

Friday, December 27, 2013

POLCONST - Constructible Regular Polygons

Constructible Regular Polygons

<h3 style="color: #000020; font-family: Verdana, Arial, Helvetica, sans-serif; text-align: left;"> <span style="font-weight: normal;"><span style="font-size: small;">polconst spoj or constructible regular polygons spoj.</span></span></h3>

A regular n-gon is constructible with ruler and compass if and only if  n = 2kp1p2...pt  where k and t are non-negative integers, and each pi is a (distinct) Fermat prime

Only five Fermat primes are known:
F0 = 3, F1 = 5, F2 = 17, F3 = 257, and F4 = 65537
(copied from wikipidea)
#include<stdio.h>
int main()
{
 int t;
 scanf("%d",&t);
 while(t--)
 {
  int N,temp;
  scanf("%d",&N);
  temp=N;
  while(temp % 2==0) 
   temp=temp/2;
  if(temp % 3==0)
   temp=temp/3;
  if(temp % 5==0)
   temp=temp/5;
  if(temp % 17==0)
   temp=temp/17;
  if(temp % 257==0)
   temp=temp/257;
  if(temp % 65537==0)
   temp=temp/65537;
  if(temp==1)
   printf("Yes\n");
  else
   printf("No\n");
 }
 return 0;
}



No comments:

Post a Comment

Your comment is valuable to us