All about problems in Volume 101. If there is a thread about your problem, please use it. If not, create one with its number in the subject.
Moderator: Board moderators
Moni
Experienced poster
Posts: 202 Joined: Fri Mar 22, 2002 2:00 am
Location: Chittagong. CSE - CUET
Contact:
Post
by Moni » Sat Jun 22, 2002 7:37 pm
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 !!!
10153EN
Experienced poster
Posts: 148 Joined: Sun Jan 06, 2002 2:00 am
Location: Hong Kong
Contact:
Post
by 10153EN » Sat Jun 22, 2002 8:25 pm
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.
obayashi
New poster
Posts: 33 Joined: Thu Jun 20, 2002 1:18 pm
Post
by obayashi » Sun Jun 23, 2002 10:52 am
there's a simple solution;)
Time makes a fool of memory
And yet my memories still shine
Moni
Experienced poster
Posts: 202 Joined: Fri Mar 22, 2002 2:00 am
Location: Chittagong. CSE - CUET
Contact:
Post
by Moni » Tue Jul 02, 2002 9:54 pm
obayashi wrote: there's a simple solution;)
Can you present some of it's hints
!!!
We are all in a circular way, no advances, only moving and moving!
Picard
Learning poster
Posts: 96 Joined: Mon Jun 24, 2002 1:22 pm
Location: Hungary
Contact:
Post
by Picard » Tue Jul 02, 2002 10:19 pm
multiply as on paper (in school), but here you know the result digits
Moni
Experienced poster
Posts: 202 Joined: Fri Mar 22, 2002 2:00 am
Location: Chittagong. CSE - CUET
Contact:
Post
by Moni » Wed Jul 03, 2002 8:49 pm
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?
We are all in a circular way, no advances, only moving and moving!
obayashi
New poster
Posts: 33 Joined: Thu Jun 20, 2002 1:18 pm
Post
by obayashi » Sun Aug 11, 2002 9:12 am
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.
Time makes a fool of memory
And yet my memories still shine
Jalal
Learning poster
Posts: 65 Joined: Sun Jun 02, 2002 8:41 pm
Location: BANGLADESH
Contact:
Post
by Jalal » Sat Oct 19, 2002 9:55 pm
U have made just a stupid mistake!!!!
try this
After a=(a*10)+1;
why like astupid dont wrote this
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;
}
Last edited by
Jalal on Wed Mar 17, 2004 10:43 am, edited 1 time in total.
Maarten
Experienced poster
Posts: 108 Joined: Sat Sep 27, 2003 5:24 pm
Post
by Maarten » Sun Nov 09, 2003 11:12 pm
obayashi wrote: there's a simple solution;)
Does 'simple' mean O(1) solution? My solution is O(number of digits in result)
neo_tohin
New poster
Posts: 5 Joined: Wed Dec 31, 2003 11:24 am
Location: Bangladesh
Contact:
Post
by neo_tohin » Wed Jan 07, 2004 6:38 am
Jalal bhai apna to er ekta stupid
Bhagsash upopado bhola gaachan
Moni, use this method
3 | 111 | 37
9
-----------------
21
21
--------------------
0
lala la la la
Live to die
jaywinyeah
New poster
Posts: 19 Joined: Sun Aug 17, 2003 10:40 pm
Post
by jaywinyeah » Mon Jan 12, 2004 11:58 am
Why does that work? Why do we only need the remainder?
LL Cool Jay
The Formula Wizard
Jason Winokur
Nishita
New poster
Posts: 1 Joined: Sat Mar 13, 2004 4:25 pm
Location: India
Contact:
Post
by Nishita » Sun Mar 14, 2004 8:19 pm
Hello neo_tohin:
Could u tell me what is the
"Bhagsash upopado". I want to know more about number theory.
Pease help me.
Nishita
Note: Please remove the code from board.
Jalal
Learning poster
Posts: 65 Joined: Sun Jun 02, 2002 8:41 pm
Location: BANGLADESH
Contact:
Post
by Jalal » Mon Mar 15, 2004 6:42 pm
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.......
Navid666
New poster
Posts: 7 Joined: Tue Jul 26, 2005 8:06 pm
Contact:
Post
by Navid666 » Fri Jul 29, 2005 9:35 pm
my code dont work for some input like 27 and i dont know what should i do to fix it???? :-/ please help me ... thanks
Last edited by
Navid666 on Mon Aug 01, 2005 1:49 pm, edited 1 time in total.
=;GOOD LUCK=;
NAvidOP
Navid666
New poster
Posts: 7 Joined: Tue Jul 26, 2005 8:06 pm
Contact:
Post
by Navid666 » Fri Jul 29, 2005 9:42 pm
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!
=;GOOD LUCK=;
NAvidOP