Skip to main content

solution of-BOMARBLE - D - Playing with Marbles on spoj

BOMARBLE - D - Playing with Marbles



Pablo was assigned in his class to construct pentagons inside pentagons with marbles but he doesn’t know how many marbles he will need. He knows that for one pentagon he needs 5 marbles
The only way he knows to insert a second pentagon is putting a marble in the middle of each segment and drawing three lines as shown. He puts a marble in the intersecting lines and removes them. To insert a third pentagon inside he first divides all segments in two including the ones that are not needed, and repeats the procedure. Drawing a second pentagon will require 12 marbles. A third pentagon will require 22 marbles. Given the information of how many pentagons will be created, write a program to calculate the number of marbles needed.

solution-

#include<stdio.h>
int main()
{int n,k;

while(scanf("%d",&n)!=EOF)
{
if(n==0)
break;
else
{
k=5*n+((n-1)*(3*n-2))/2;
printf("%d\n",k);
}
}
return 0;
}

example-

input-
1
2
3
0

output-

5
12
22

explain-

you should find pattern
you can see marble inside of pentagonal is in ap
so you can easily
find

Comments

Popular posts from this blog

top 10 youtuber of india

        TOP 10 YOUTUBER OF INDIA we are live in that age where everyone is know about youtube.Most of the people open youtube minimum twice in a day. Competition on youtube is so high that people are judge other people by know that which channel he visit. In india jio telecom increase the lavel of youtube. 1.AMIT BHADANA current subscribers-13M TYPE OF CHANNEL-comedy 13 millions is not a just a small number.Amit is very popular everywhere city or village. Amit has a big no of followers. the good things about there videos is that he never use a single words of abuse. we love him. 2.BB KI VINES-BHUVAN BAM current subscribers-12M TYPE OF CANNEL-comedy now come the best youtuber of student specially engineers. in his videos he play many role that is extra ordinary.his comedy is super he has a very good sense of humour.he is very stylish. 3.GOURAV- CHANNEL NAME- TECHNICAL GURUJI               ...