Public submissions
Source code of every submission to this problem in this contest will be visible for everyone since 4012-10-16 21:00:00.

GAMES - How Many Games?

A player has played unknown number of games. We know the average score of the player (sum of scores in all the games / number of games). Find the minimum number of games the player should have played to achieve that average.

The player can score any non-negative integer score in a game.

Input

The first line consists of an integer t, the number of test cases. Each test case consists of a single rational number which represents the average score of the player.

Output

For each test case, find the minimum number of matches the player should have played to achieve that average.

Constraints

1 <= t <= 1000
1 <= average <= 1000000 (maximum 4 digits after the decimal place)

Example

Input:
3
5
5.5
30.25

Output:
1
2
4

Added by:cegprakash
Date:2012-10-12
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:ADA95 ASM32 GAWK C CSHARP C++ 4.3.2 CPP14-CLANG C99 CLPS CLOJURE LISP sbcl LISP clisp D-CLANG ERL FSHARP FORTRAN GO HASK ICON ICK JS-RHINO JS-MONKEY LUA NICE NIM NODEJS OCAML PAS-FPC PERL PERL6 PHP PICO PIKE PRLG-swi PYTHON PYPY PYTHON3 RUBY SCM guile SCM qobi SED TCL VB.NET WHITESPACE
Public source code since: 4012-10-16 21:00:00

hide comments
2015-05-22 22:06:40 Tony Stark
#include<iostream>
#include<math.h>
#include<string.h>
int gcd(int a,int b)
{
return (b==0)?a:(gcd(b,a%b));
}
using namespace std;
main()
{
int test;
cin>>test;
while(test--)
{
int sum=0;
int i=1;
char str[5000];
cin>>str;

for(i=0;;i++)
{

if(str[i]=='.')
{
for(int j=0;j<4;j++,i++)
{
if(str[i+1]=='\0')
break;
sum=sum+(str[i+1]-'0')*pow(10,3-j);
// cout<<sum<<" ";
}
break;
}

}
// cout<<sum<<endl;

int x=gcd(sum,10000);
cout<<10000/x<<endl;
}
}
2013-01-24 06:04:13 vedulla krishna
can anyone tell me ...whats wrong in my code ...
#include<iostream>
#include<math.h>

using namespace std;

int main()
{
double avg,i,res,t;
cin>>t;
while(t--)
{
res=1.1;
cin>>avg;
if(avg==0) cout<<0<<endl;
else{
for(i=1;floor(res)!=res;i++)
res=avg*i;
cout<<i-1<<endl;
}
}
return 0;
}


2012-10-16 18:02:02 Charizard_
answer for 0.0001???

cegprakash: it's obvious. 10000

Last edit: 2012-10-16 18:48:46
2012-10-16 16:26:16 cegprakash
personal hint to avoid floating point errors : try to read the numbers as strings

Last edit: 2012-10-16 16:29:35
2012-10-16 15:47:44 prashanth
same answer as below still WA.:(

cegprakash: Sorry, I cannot provide the test cases for which you fail specifically :(

Last edit: 2012-10-16 16:32:37
2012-10-16 15:35:31 cegprakash
0.98 50
0.68 25
0.63 100
2012-10-16 15:27:42 prashanth
more test cases..
2012-10-16 14:48:46 cegprakash
No. The average is not rounded off. The given average is accurate.

For 999999.9999, the answer is 10000.
2012-10-16 14:44:57 Pandian
So, the average will be rounded off ? if it is 4.66.. will it be 4.6666 or 4.6667 ?
2012-10-16 14:36:37 cegprakash
Note that the average given is accurately calculated.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.