Factorial
Problem code: FCTRLAll submissions for this problem are available.
The most important part of a GSM network is so called Base Transceiver Station (BTS). These transceivers form the areas called cells (this term gave the name to the cellular phone) and every phone connects to the BTS with the strongest signal (in a little simplified view). Of course, BTSes need some attention and technicians need to check their function periodically.The technicians faced a very interesting problem recently. Given a set of BTSes to visit, they needed to find the shortest path to visit all of the given points and return back to the central company building. Programmers have spent several months studying this problem but with no results. They were unable to find the solution fast enough. After a long time, one of the programmers found this problem in a conference article. Unfortunately, he found that the problem is so called "Traveling Salesman Problem" and it is very hard to solve. If we have N BTSes to be visited, we can visit them in any order, giving us N! possibilities to examine. The function expressing that number is called factorial and can be computed as a product 1.2.3.4....N. The number is very high even for a relatively small N.The programmers understood they had no chance to solve the problem. But because they have already received the research grant from the government, they needed to continue with their studies and produce at least some results. So they started to study behavior of the factorial function.For example, they defined the function Z. For any positive integer N, Z(N) is the number of zeros at the end of the decimal form of number N!. They noticed that this function never decreases. If we have two numbers N1<N2, then Z(N1) <= Z(N2). It is because we can never "lose" any trailing zero by multiplying by any positive number. We can only get new and new zeros. The function Z is very interesting, so we need a computer program that can determine its value efficiently.Input
There is a single positive integer T on the first line of input (equal to about 100000). It stands for the number of numbers to follow. Then there are T lines, each containing exactly one positive integer number N, 1 <= N <= 1000000000.Output
For every number N, output a single line containing the single non-negative integer Z(N).Example
Sample Input:6 3 60 100 1024 23456 8735373
Sample Output:0 14 24 253 5861 2183837
Date: 2008-12-01 Time limit: 8 Source limit: 50000 #include<iostream>- # define max 100000
- using namespace std;
- int main()
- {
- unsigned long n,i;
- unsigned long arr[max],arr1[max],b[max];
- cin>>n;
- for(i=0;i<n;i++)
- cin>>arr[i];
- for(i=0;i<n;i++)
- {
- b[i]=0;
- while(arr[i]>0)
- {
- arr[i]=arr[i]/5;
- b[i]=b[i]+arr[i];
- }
- arr1[i]=b[i];
- }
- for(i=0;i<n;i++)
- cout<<arr1[i]<<"\n";
- }
TECHNOLOGY ROCKZZZZZZZ
Tuesday, 17 January 2012
- ques
Odd
Problem code: DCE05All submissions for this problem are available.
The captain of the ship TITANIC is a little .... off the track. He needs to select the crew for the ship. But everyone seems to be eligible. So to test their intelligence, he plays a game.
The contestants have to stand in a line. They are given the numbers in the order in which they stand, starting from 1. The captain then removes all the contestants that are standing at an odd position.
Initially, standing people have numbers - 1,2,3,4,5...
After first pass, people left are - 2,4,...
After second pass - 4,....
And so on.
You want to board the ship as a crew member. Given the total number of applicants for a position, find the best place to stand in the line so that you are selected.Input
First line contains the number of test cases t (t<=10^6). The next t lines contain integer n, the number of applicants for that case. (n<=10^9)Output
Display t lines, each containg a single integer, the place where you would stand to win a place at TITANIC.Example
Input: 2 5 12 Output: 4 8
solution#include<iostream> - using namespace std;
- int main()
- {
- int no,i,m;
- cin>>no;
- while(no--)
- {
- cin>>i;
- m=1;
- while(m<=i)
- {
- m=m*2;
- }
- cout<<m/2<<endl;
- }
- }
Monday, 16 January 2012
ques---------->
The captain of the ship TITANIC is a little .... off the track. He needs to select the crew for the ship. But everyone seems to be eligible. So to test their intelligence, he plays a game.
The contestants have to stand in a line. They are given the numbers in the order in which they stand, starting from 1. The captain then removes all the contestants that are standing at an odd position.
Initially, standing people have numbers - 1,2,3,4,5...
After first pass, people left are - 2,4,...
After second pass - 4,....
And so on.
You want to board the ship as a crew member. Given the total number of applicants for a position, find the best place to stand in the line so that you are selected.
The contestants have to stand in a line. They are given the numbers in the order in which they stand, starting from 1. The captain then removes all the contestants that are standing at an odd position.
Initially, standing people have numbers - 1,2,3,4,5...
After first pass, people left are - 2,4,...
After second pass - 4,....
And so on.
You want to board the ship as a crew member. Given the total number of applicants for a position, find the best place to stand in the line so that you are selected.
Input
First line contains the number of test cases t (t<=10^6). The next t lines contain integer n, the number of applicants for that case. (n<=10^9)
Output
Display t lines, each containg a single integer, the place where you would stand to win a place at TITANIC.
Example
Input: 2 5 12 output
4
8
soln---------->
#include<iostream>
using namespace std;
int output(long long int *,long long int);
void removeodd(long long int *arr,long long int b)
{
long long int arr2[b],j,k=2;
if(b%2!=0)
{
for(j=1;j<=b;j++)
{
arr2[j]=arr[k];
k+=2;
}
output(arr2,b);
}
else
{
for(j=1;j<=b-1;j++)
{
arr2[j]=arr[k];
k+=2;
}
output(arr2,b);
}
}
int output(long long int *arr,long long int b)
{
if(b%2==0)
{
if((b/2)==1)
cout<<arr[1]<<"\n";
else
removeodd(arr,b/2);
}
else
{
if((b/2+1)==1)
cout<<arr[1];
else
removeodd(arr,(b/2+1));
}
}
int main()
{ unsigned long n;
cin>>n;
long long int b[n];
for(long long int g=1;g<=n;g++)
{
cin>>b[g];
}
for(long long int f=1;f<=n;f++)
{
long long int arr[b[f]];
for(long long int i=1;i<=b[f];i++)
arr[i]=i;
output(arr,b[f]);
}
system("pause");
}
Subscribe to:
Posts (Atom)