Page 1 of 3

10127 - Ones

Posted: Sat Jun 22, 2002 7:37 pm
by Moni

Code: Select all

#include<iostream.h>
#include<math.h>

int main()
{

unsigned long int n;

while(cin>>n)
{
	long double a=1;
	unsigned long int t=0;

	while(fmod(a,n)!=0)
	{
		a=(a*10)+1;
		t++;
	}

	cout << (t+1) << endl;
                n=0;
}

	return 0;
}
Hmm! I am tired what might be the answer without this !!! :roll:

Posted: Sat Jun 22, 2002 8:25 pm
by 10153EN
Hello, why do you think that a long double variable can store the value without overflow?

The answer may be of hundreds of digits actually.

Posted: Sun Jun 23, 2002 10:52 am
by obayashi
there's a simple solution;)

Posted: Tue Jul 02, 2002 9:54 pm
by Moni
obayashi wrote:there's a simple solution;)

Can you present some of it's hints :wink: !!!

Posted: Tue Jul 02, 2002 10:19 pm
by Picard
multiply as on paper (in school), but here you know the result digits

Posted: Wed Jul 03, 2002 8:49 pm
by Moni
Can I use the basic rule of division ?
That is :
How many times you can subract one data from another and at the last subtraction you will get only zero, is the division.


What is you idea? :-?

Posted: Sun Aug 11, 2002 9:12 am
by obayashi
do not think 2 much about the number of digits that requires storage.

just check the remainder and that will be ok.

this problem has just something to do with the remaider. :wink:

Posted: Sat Oct 19, 2002 9:55 pm
by Jalal
U have made just a stupid mistake!!!!
try this
:wink:
After a=(a*10)+1;
why like astupid dont wrote this :P
a=fmod(a,n);

#include<iostream.h>
#include<math.h>

int main()
{

unsigned long int n;

while(cin>>n)
{
long double a=1;
unsigned long int t=0;

while(fmod(a,n)!=0)
{
a=(a*10)+1;
a=fmod(a,n);
t++;
}

cout << (t+1) << endl;
n=0;
}

return 0;
}

Posted: Sun Nov 09, 2003 11:12 pm
by Maarten
obayashi wrote:there's a simple solution;)
Does 'simple' mean O(1) solution? My solution is O(number of digits in result)

Ha ha ha ha ha ha ha?????????????????????

Posted: Wed Jan 07, 2004 6:38 am
by neo_tohin
Jalal bhai apna to er ekta stupid 8)

Bhagsash upopado bhola gaachan :lol:

Moni, use this method

3 | 111 | 37
9
-----------------
21
21
--------------------
0


lala la la la :D

Posted: Mon Jan 12, 2004 11:58 am
by jaywinyeah
Why does that work? Why do we only need the remainder?

Posted: Sun Mar 14, 2004 8:19 pm
by Nishita
Hello neo_tohin:

Could u tell me what is the "Bhagsash upopado". I want to know more about number theory.

Pease help me.

Nishita
:cry:

Note: Please remove the code from board.

Posted: Mon Mar 15, 2004 6:42 pm
by Jalal
neo_tohin!
its really nice to get a reply about 2 years later on a topic!
anyway i really never heard about Bhagsash upopado".
U should know I m not smart like u..............
wt is that plz. explain.......

10127 Ones problem

Posted: Fri Jul 29, 2005 9:35 pm
by Navid666
my code dont work for some input like 27 and i dont know what should i do to fix it???? :-/ please help me ... thanks

Posted: Fri Jul 29, 2005 9:42 pm
by Navid666
the floor and ceil of one number is equal or differnce of them is one!!!
so when you compair last two digit it means you compair them...before this i compaired whole of them and got same answer!