COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

Factor of a number

• Email
• Follow

```Good evening i have quick question:  I want to add a feature which will
allow me to  to show the factor of a number inputted
What would be the best way to  do this by implementing this into my Prime
Calculator Method or create a new method?

class PrimeCalculator
{

PrimeCalculator(long number)
{

long nextprime;

if (isPrime(number))
{
showResult (number + " is a prime.");
}
else{
nextprime = number + 1;
if (nextprime % 2 == 0)
nextprime++;

while(!isPrime(nextprime))
nextprime += 2;

showResult (number + " is not a prime", "Next Number is "+ nextprime);
}
}

```
 0

See related articles to this posting

```"J" <silky_mez@yahoo.com> wrote in message
news:4qudnfw4jKd5EuHbnZ2dnUVZ_sWdnZ2d@comcast.com...
> Good evening i have quick question:  I want to add a feature which will
> allow me to  to show the factor of a number inputted
> What would be the best way to  do this by implementing this into my Prime
> Calculator Method or create a new method?

there may be more than one factor - why not just have a static method so you
don't have to create an object for each calculation.
this method returns a list of factors separated by spaces for the number in
a string.

public static String listFactors(int n){
String out = "1";
for ( int i = 2; i < n; i++){
if (n % i == 0 ){
out += " " + i;
}
}
return out;
}

```
 0

```Hal Rosser wrote:
> "J" <silky_mez@yahoo.com> wrote in message
> news:4qudnfw4jKd5EuHbnZ2dnUVZ_sWdnZ2d@comcast.com...
>> Good evening i have quick question:  I want to add a feature which will
>> allow me to  to show the factor of a number inputted
>> What would be the best way to  do this by implementing this into my Prime
>> Calculator Method or create a new method?
>
> there may be more than one factor - why not just have a static method so you
> don't have to create an object for each calculation.
> this method returns a list of factors separated by spaces for the number in
> a string.
>
> public static String listFactors(int n){
>     String out = "1";
>     for ( int i = 2; i < n; i++){
>          if (n % i == 0 ){
>               out += " " + i;
>           }
>      }
>      return out;
> }

Bear in mind that this technique uses String concatenation which litters the
heap with created objects, negating your claim of " you don't have to create
an object for each calculation."  In point of fact, you are creating three
with each iteration.

--
Lew
```
 0
Reply lew3286 (19) 6/23/2007 12:19:38 PM

```Hal Rosser wrote:
> "J" <silky_mez@yahoo.com> wrote in message
> news:4qudnfw4jKd5EuHbnZ2dnUVZ_sWdnZ2d@comcast.com...
>> Good evening i have quick question:  I want to add a feature which will
>> allow me to  to show the factor of a number inputted
>> What would be the best way to  do this by implementing this into my Prime
>> Calculator Method or create a new method?
>
> there may be more than one factor - why not just have a static method so you
> don't have to create an object for each calculation.
> this method returns a list of factors separated by spaces for the number in
> a string.
>
> public static String listFactors(int n){
>     String out = "1";
>     for ( int i = 2; i < n; i++){
>          if (n % i == 0 ){
>               out += " " + i;
>           }
>      }
>      return out;
> }

Bear in mind that this technique uses String concatenation which litters the
heap with created objects, negating your claim of " you don't have to create
an object for each calculation."  In point of fact, you are creating two with
each iteration.

--
Lew
```
 0

```"Lew" <lew@lewscanon.nospam> wrote in message
news:QN-dnTh_kbmSjeDbnZ2dnUVZ_t3inZ2d@comcast.com...
>> public static String listFactors(int n){
>>     String out = "1";
>>     for ( int i = 2; i < n; i++){
>>          if (n % i == 0 ){
>>               out += " " + i;
>>           }
>>      }
>>      return out;
>> }
>
>
> Bear in mind that this technique uses String concatenation which litters
> the heap with created objects, negating your claim of " you don't have to
> create an object for each calculation."  In point of fact, you are
> creating two with each iteration.

Right you are.
I should have used a StringBuilder.
But the OP seemed to need a nudge away from his original course.

```
 0

```Hmmm....  That gives me an idea what to do, but i"m not quite sure. I'll
fidget around with it and report back to you.

"Hal Rosser" <hmrosser@bellsouth.net> wrote in message
news:sEhfi.2879\$s8.897@bignews1.bellsouth.net...
>
> "Lew" <lew@lewscanon.nospam> wrote in message
> news:QN-dnTh_kbmSjeDbnZ2dnUVZ_t3inZ2d@comcast.com...
>>> public static String listFactors(int n){
>>>     String out = "1";
>>>     for ( int i = 2; i < n; i++){
>>>          if (n % i == 0 ){
>>>               out += " " + i;
>>>           }
>>>      }
>>>      return out;
>>> }
>>
>>
>> Bear in mind that this technique uses String concatenation which litters
>> the heap with created objects, negating your claim of " you don't have to
>> create an object for each calculation."  In point of fact, you are
>> creating two with each iteration.
>
> Right you are.
> I should have used a StringBuilder.
> But the OP seemed to need a nudge away from his original course.
>
>

```
 0

5 Replies
158 Views

Similar Articles

12/19/2013 6:07:59 PM
page loaded in 22684 ms. (0)

Similar Artilces:

Factor Analysis: Number of Factors
Hi, I have a very basic question in factor analysis - how many factors to menti= on in nfactor option while running a proc factor I can select how many factors I want to analyze by checking the scree plot = or by help of eigen value (>1), but if I run proc factor with nfactor=3D10= or nfactor=3D50 then loading on factors changes significantly and this eve= n changes the business definition of my factors. Please help me understand how to choose the optimal value of nfactor or if = there is a way by which we derive that value than what is that way Regards, Rajat _______________________...

Re: Factor Analysis: Number of Factors #3
--- On Mon, 7/6/09, Peter Flom <peterflomconsulting@MINDSPRING.COM> wrote: > From: Peter Flom <peterflomconsulting@MINDSPRING.COM> > Subject: Re: Factor Analysis: Number of Factors > To: SAS-L@LISTSERV.UGA.EDU > Date: Monday, July 6, 2009, 6:18 AM > "Mathur, Rajat" <Rajat.Mathur@DIAMONDCONSULTANTS.COM> > wrote > > > > >I have a very basic question in factor analysis - how > many factors to mention in nfactor option while running a > proc factor > > > > Basic, but far from simple or easy! True, very true!!! > &...

All Factors of a number
Following is a test code that I am trying to get down to a set of instructions that will allways put all of the factors of a number in a table or list. bt contains all of the factors if I multiply each list entry, however I cannot accomplish that with a single line, as an example I have broken into the three lists needed for this example. The results of each "Times@@" is what I am after all placed into one table. All of my attempts have proved disasterous, I am new to Mathematica and could do this with nested loops in any programming language, but this has me stumped. Thanx!...

Concatenation of prime factors of numbers
Can someone help me with this trick? I would like to create the following sequence, based on FactorInteger: 2,3,22,5,23,7,222,33,25,11,223,13,27,35,2222, ... where each term is the concatenation of the prime factors of n. Thanks, Diana Hello Diana, that can be done by: -FactorInteger -Convert the factor to a string and duplicate the string as many times as the exponent indicates. This produces a list -Flatten superfluous braces - Apply StringJoin to the list of strings -convert the strings to numbers using ToExpression: - the above procedure ma...

how do I factor a number down to one digit?
I'm trying to write a numerology program where I have each letter identified by a numerical value like a=1 b=2 c=3 as so forth. I then input a name. How do I treat each letter as a single value? That is, instead of print myname I have to do a print m+y+n+a+m+e which returns a number. I next want to convert the resulting two or three digit number to a single digit. Like 123 would be 1+2+3 returning a 5. I hope this isn't too stupid of a question. Allan>I hope this isn't too stupid of a question. It's a simple problem, but it's not a stupid question, this is a possible ...

Re: Working with factors of triangular numbers.
On 7/8/07 at 6:14 AM, akoz@mimuw.edu.pl (Andrzej Kozlowski) wrote: >In fact, one more remark (its hard to stop adding these remarks!). >Clearly if you are computing the values of T[n] for several >different n, this is an inefficient way to proceed, because you if >we know that t1 is the smallest triagular number that can be >factored as a product of n factors than we know also that no >triangular number smaller than t1 can be factored as a product of >(n+1) factors. It is then better to proceed like this. >t[a_] := k /. ToRules[Reduce[k (k + 1)/2 == a &&...

HP48GX Routine to Extract Prime Number Factors
I have an HP-41C routine out of the PPC ROM book that factors an integer into prime number factors. I am in the process of reverse engineering it into HP-48 code, but am curious to know if there might be a similar routine out in our HP cyber space. Any one know? Thanks. jwferman@ties2.net On Thu, 11 Dec 2008 23:14:09 -0600, Jack wrote: > I have an HP-41C routine out of the PPC ROM book that factors an > integer into prime number factors. I am in the process of reverse > engineering it into HP-48 code, but am curious to know if there might > be a similar routine out in our HP cyb...

equation number, table number, figure number linked to the same paragraph number
I have a paragraph number, example A-XXX Then I want to have equations like: .... Eq A-1 .... Eq A-2 ... liked to this paragraph And also ... fig A-1 .... fig A-2 ...linked only to this paragraph .... At the end. I want to have... A-XXX .... Eq A-1 .... fig A-1 .... fig A-2 .... Eq A-2 .... Eq A-3 .... fig A-3 B-XXX .... Eq B-1 .... fig B-1 .... Eq A-2 .... Eq A-3 .... fig B-2 Thanks for ideas On Sat, 17 Nov 2007 23:22:15 +0100, value <####@wanadoo.fr> wrote: > I have a paragraph number, example > > A-XXX > > T...

number of processors, number of cores, how can I get these numbers?
hi, I have two questions, 1/ is there any OS function which return me the number of core on each processor on my computer (callable from C++) 2/ is there any OS function which return me the number of processor on my computer (callable from C++) By OS I mean Windows (XP and later), Linux, Solaris... Thanks XS Jekyll wrote: > hi, > I have two questions, > 1/ is there any OS function which return me the number of core on each > processor on my computer (callable from C++) By definition, OS functions are not part of Standard C++, and are therefore off-topic in comp.lang.c++. Ask i...