@Ahmad: This is known as a Collatz Sequence. It is hypothesized that the
sequence will eventually reach 1 for every starting number N. So here is an
algorithm to find where they meet, using O(1) space:
1. Generate each sequence and count the number of iterations required to
reach 1. You need n
The normal meaning of "in place" is only constant additional storage.
You're using much more than that.
On Aug 15, 12:52 pm, Don wrote:
> #include
> #include
>
> int main(int argc, char* argv[])
> {
> char line[500];
> char tmp[500];
> char *words[100];
> int wor
First reverse the whole sentence and then reverse every word of the
sentence
Example : "I am a programmer"
Step 1 Reverse entire sentence
"remmargorp a ma I"
Step 2 Now reverse every word in a sentence
programmer a am I
Complexity O(n)
On Mon, Aug 15, 2011 at 10:22 PM, Don wrote:
> #includ
#include
#include
int main(int argc, char* argv[])
{
char line[500];
char tmp[500];
char *words[100];
int wordCount = 0;
char *p, *wordStart=0;
printf("Enter string:");
fgets(line,500,stdin);
for(p = line; *p; ++p)
{
#include "stdafx.h"
#include
using namespace std;
typedef pair node;// first is max. second is min
typedef int m_iterator;
node maxmin(int *a,m_iterator start,m_iterator end)
{
if(start==end-1){ //only hava one elements
return make_pair(a[start],a[start]);
}
-Original Message-
> From: algogeeks@googlegroups.com [mailto:algoge...@googlegroups.com] On
>
> Behalf Of Dave
> Sent: Friday, December 10, 2010 8:10 PM
> To: Algorithm Geeks
> Subject: [algogeeks] Re: program for evaluation of remainders
>
> @Ankit: Why not just use th
, 2010 8:10 PM
To: Algorithm Geeks
Subject: [algogeeks] Re: program for evaluation of remainders
@Ankit: Why not just use the algorithm I proposed in
http://groups.google.com/group/algogeeks/msg/2941ab071a39517c:
x = 0;
for( i = (n < N ? n : N) ; i > 0 ; --i )
x = (i * x + i) % n;
Dave
@Dave
Because he wants to optimize it
if we can get the boundary of running time, we'll get the faster
algorithm
haxxpop
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To uns
@Ankit: Why not just use the algorithm I proposed in
http://groups.google.com/group/algogeeks/msg/2941ab071a39517c:
x = 0;
for( i = (n < N ? n : N) ; i > 0 ; --i )
x = (i * x + i) % n;
Dave
On Dec 10, 4:23 am, ankit sablok wrote:
> @Dave
> we will use residues then i think the property of m
@Dave
we will use residues then i think the property of modulus
1!mod997 + 2!mod997 + 3!mod997 .. + 997!mod997
i just proposed the solution using congruences for the case
n wrote:
> @Ankit: So how does that work with, e.g., N = n = 997? I.e., what is
> the calculation?
>
> Dave
>
> On Dec 8,
@jai gupta
why is this work??
I think it just calculates (N+1)! %n
haxxpop
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to
algog
@Dave
I like this. use mem just O(1) , my algo use O(N). Thxx
haxxpop
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+u
997 is a prime number, so the calculation must be (1!+2!+...+996!) mod
997
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to
algogee
@Ankit: So how does that work with, e.g., N = n = 997? I.e., what is
the calculation?
Dave
On Dec 8, 11:33 am, ankit sablok wrote:
> @ all the authors thanx for the suggestions actually wt i know about
> the problem is i think we can solve the problem mathematically if we
> know about congruence
@ all the authors thanx for the suggestions actually wt i know about
the problem is i think we can solve the problem mathematically if we
know about congruences
for instance
if N=100
1! + 2! + . + 100!
and n=12
we find that
4!mod24=0
hence the above equation reduces to the
(1!+2!+3!)mod
Using this idea makes my solution into
x = 0;
for( i = (n < N ? n : N) ; i > 0 ; --i )
x = (i * x + i) % n;
Dave
On Dec 8, 7:27 am, Ashim Kapoor wrote:
> Let me try. Any thing involving n would leave no remainder.
>
> so (1 + 2 ! + ... + n ! + + N !) mod n = (1 + 2 ! + ... + (n-1)! )
rem=1;
for(j=3;j<=N+1;j++)
rem=(rem*j)%n;
return rem;
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@googl
@Ankit: Try this:
x = 0;
for( i = N ; i > 0 ; --i )
x = (i * x + i) % n;
Dave
On Dec 8, 7:19 am, ankit sablok wrote:
> Q) can anyboy find me the solution to this problem
>
> Given an integer N and an another integer n we have to write a program
> to find the remainder of the following probl
Hey Admin,
Please ban this fellow.
He's just using the group for his own well being and spamming the group
!!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send emai
19 matches
Mail list logo