473,396 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Largest Integer Divisor

I need to drawraw a flowchart for a algorithm which finds the largest proper divisor of n (that is, the largest m such that 1 <= m < n and m evenly divides n). You can use the % operator: recall that n % m is the remainder when n is divided by m.

I need to test it on numbers such as 8,876,044,532,898,802,067 and 2,305,843,009,213,693,951..

so far I have
public class xc14 {

public static long maxDiv(long n )
{
int m = 2;
while(m <= (int) Math.sqrt(n))
{
// ...
}
return 1;
}

can anyone help?
Nov 6 '07 #1
7 4037
r035198x
13,262 8TB
I need to drawraw a flowchart for a algorithm which finds the largest proper divisor of n (that is, the largest m such that 1 <= m < n and m evenly divides n). You can use the % operator: recall that n % m is the remainder when n is divided by m.

I need to test it on numbers such as 8,876,044,532,898,802,067 and 2,305,843,009,213,693,951..

so far I have
public class xc14 {

public static long maxDiv(long n )
{
int m = 2;
while(m <= (int) Math.sqrt(n))
{
// ...
}
return 1;
}

can anyone help?
So where have you used the % operator like was suggested?
Nov 6 '07 #2
lol thats why im confused....
Nov 8 '07 #3
r035198x
13,262 8TB
lol thats why im confused....
But you are trying to find numbers which divide perfectly into a given number N, For those numbers N % number is zero.
Nov 8 '07 #4
JosAH
11,448 Expert 8TB
Suppose for a number N you have to find the largest proper divisor; this is equivalent
to finding its smallest proper divisior; suppose the smalles one is 'S'; this implies
that S*L == N where L happens to be the largest proper divisor of N.

kind regards,

Jos
Nov 8 '07 #5
r035198x
13,262 8TB
Suppose for a number N you have to find the largest proper divisor; this is equivalent
to finding its smallest proper divisior; suppose the smalles one is 'S'; this implies
that S*L == N where L happens to be the largest proper divisor of N.

kind regards,

Jos
Spoil sport
Nov 8 '07 #6
JosAH
11,448 Expert 8TB
Spoil sport
I really thought that this thread would brings us to BigIntegers and such; what
I wrote is trivial isn't it?

kind regards,

Jos
Nov 8 '07 #7
r035198x
13,262 8TB
I really thought that this thread would brings us to BigIntegers and such; what
I wrote is trivial isn't it?

kind regards,

Jos
We'll need to get to BigIntegers at some point.

You couldn't have written anything more trivial if you had tried.
Nov 8 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Nicholas | last post by:
How can I get the largest possible value of the Integer Constants and use it in the program for these types: 1. int 2. long 3. unsigned short Thanks
9
by: Darius Fatakia | last post by:
hi, i'm new to MS Visual Studio and C++ but not to C programming in general. i'm trying to divide two integers and get their actual quotient (eg 5/3 = 1.666667 etc). i thought i had type cast...
18
by: Toby Newman | last post by:
I need to randomly choose one of four paths in my program. Using the tools I know, the best way I can think to do it is by doing something like the following: //==============================...
2
by: Ben | last post by:
Hi, I have an interesting example from my debugger. I have 2 variables: sourcewidthnet and targetwidthnet. Notice the results in the debugger. I'm going to be forced to use the int function of the...
3
by: HEMH6 | last post by:
Who can help solve this problem??? Finding the Largest Value (a) write a function, largest(), that returns the largest value in a signed integer array. The array and its size are passed as...
8
by: Candace | last post by:
I am using the following code to pick off each digit of a number, from right to left. The number I am working with is 84357. So for the first iteration it should return the number 7 and for the...
9
by: PengYu.UT | last post by:
Hi, The usually integer division will round the result to the biggest integet smaller than the float version division.For example, 10/3 = 3. I'm wondering if there is any easy way to round it...
4
by: sdlt85 | last post by:
Hi, Can someone help me with an idea on how to start writing a C++ code for generating greatest common divisor and the linear combination of two intergers represented as gcd(m, n)= mx + ny and...
8
by: MLH | last post by:
Is there any built-in FN for returning largest value in a group of say 2 - 10 values? Lets say I want a FN something like MaxVal(5, 7, 9, 3, 12) or perhaps MaxVal(79,34). I would wanna see return...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.