## 10127 - Ones

Moderator: Board moderators

Moni
Experienced poster
Posts: 202
Joined: Fri Mar 22, 2002 2:00 am
Location: Chittagong. CSE - CUET
Contact:

### 10127 - Ones

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:
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
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:
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:
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:
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
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
Contact:
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
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
Contact:

### Ha ha ha ha ha ha ha?????????????????????

Jalal bhai apna to er ekta stupid

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
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:
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
Contact:
neo_tohin!
its really nice to get a reply about 2 years later on a topic!
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:

### 10127 Ones problem

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:
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