473,386 Members | 1,763 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,386 software developers and data experts.

Simple simple program error...please help

In my simple program I am getting this error..please help

I am trying to find integers where 65537i + 3551j = 1

error: cannot convert `__complex__ int' to `long int' in
assignment
#include <iostream>
#include <complex>
#include <cmath>

using namespace std;

int main ()
{
long x=0;
int y=0;

for (long i=0; i<65537; i++)
{
for (long j=0; j<3511; j++)
{
x=65337i + 3511j;
if (x=1)
cout <<"i: "<< i << " j: "<< j<< endl;
}
}

return 0;
}

Nov 1 '05 #1
14 2140

<ta******@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
In my simple program I am getting this error..please help

I am trying to find integers where 65537i + 3551j = 1

error: cannot convert `__complex__ int' to `long int' in
assignment
#include <iostream>
#include <complex>
#include <cmath>

using namespace std;

int main ()
{
long x=0;
int y=0;

for (long i=0; i<65537; i++)
{
for (long j=0; j<3511; j++)
{
x=65337i + 3511j;
What is this? 3511j is not a number. 65537i is probably not a number,
although it might be 65537 as an int.

I think you want x = i + j; here
if (x=1)
cout <<"i: "<< i << " j: "<< j<< endl;
}
}

return 0;
}

Nov 1 '05 #2
ta******@gmail.com wrote:
In my simple program I am getting this error..please help

I am trying to find integers where 65537i + 3551j = 1

error: cannot convert `__complex__ int' to `long int' in
assignment
#include <iostream>
#include <complex>
#include <cmath>
ditch the last two headers: you do not use them anyway.

using namespace std;

int main ()
{
long x=0;
int y=0;

for (long i=0; i<65537; i++)
{
for (long j=0; j<3511; j++)
{
x=65337i + 3511j;
make that:

x= 65337*i + 3511*j;
if (x=1)
probably you mean:

if ( x == 1 )
cout <<"i: "<< i << " j: "<< j<< endl;
}
}

return 0;
}


Also:

a) running the corrected program, you might be in for a little surprise. It
will not find any numbers doing the trick: you are arbitrarily restricted
the search space for i and j, and your bounds are way off (note that it
simply cannot work for i and j both positive!).

b) You might consider reading on GCDs and the Euclidean Algorithm. It can be
extended to solve your problem.

Best

Kai-Uwe Bux

Nov 1 '05 #3
toy
Kai...thanks so much for your advice

why am i restricted? i thought that c++ integers can span a certain
space..along the lines of 2^32..???

i'm familiar with the algorithms, am i required to write my own class
to make this work?

Nov 1 '05 #4
toy wrote:
Kai...thanks so much for your advice
It's Kai-Uwe.

why am i restricted? i thought that c++ integers can span a certain
space..along the lines of 2^32..???
Please quote what you are refering to. I wrote:
a) running the corrected program, you might be in for a little surprise.
It will not find any numbers doing the trick: you are arbitrarily
restricted the search space for i and j, and your bounds are way off
(note that it simply cannot work for i and j both positive!).
And this in not even correct English. I should have written:

.... you arbitrarily restricted the search space for i and j, ...

i'm familiar with the algorithms, am i required to write my own class
to make this work?


*Which* algorithm? To make *what* work?
Best

Kai-Uwe Bux
Nov 1 '05 #5
toy
Kai-Uwe, I apologize for abbreviating your name. If I change the search
space for i and j to count downward, (as in i--, j--)..will this work?

or need i write a class or input code to execute the euclidean
algorithm in some form?

Nov 1 '05 #6
toy
Ok I changed the code to decrement i and j as opposed to
increment...the for loops will also execute until i and j are their
NEGATIVE values.

i still am not generating a solution. can u help?

Nov 1 '05 #7
toy wrote:
Ok I changed the code to decrement i and j as opposed to
increment...the for loops will also execute until i and j are their
NEGATIVE values.

i still am not generating a solution. can u help?


Sure. Here is a simple version of Euclids algorithm:

#include <iostream>
#include <algorithm>

unsigned long gcd_euclid ( unsigned long a, unsigned long b ) {
if ( b < a ) {
std::swap( a, b );
}
while ( a != 0 ) {
// now b = a*q + r for some q and r. (division with remainder)
unsigned long q = b / a;
unsigned long r = b % a;
std::cout << r << " = " << b << " - " << a << "*" << q << '\n';
b = a;
a = r;
}
return ( b );
}

int main ( void ) {
std::cout <<gcd_euclid( 65537, 3551 ) << '\n';
}

If you run this, you find: the output

1619 = 65537 - 3551*18
313 = 3551 - 1619*2
54 = 1619 - 313*5
43 = 313 - 54*5
11 = 54 - 43*1
10 = 43 - 11*3
1 = 11 - 10*1 <--- important information
0 = 10 - 1*10
The magic of the algorithm is that all these equations are actually true.
Now, you can work backwards:

1 = 11 - 10 * 1;
= 11 - ( 43 - 11 * 3 ) * 1 = 11 * 4 - 43
= ( 54 - 43 ) * 4 - 43 = 54*4 - 43*5
= 54*4 - ( 313 - 54*5) * 5 = 313*(-5) + 54*29
= ...

Another way is working forward:

1619 = 65537 - 3551*18
313 = 3551 - 1619*2 = 3551 - ( 65537-3551*18 ) * 2
= 65537*(-2) + 3551*37
54 = 1619 - 313*5
= ( 65537-3551*18 ) - ( 65537*(-2) + 3551*37 ) * 5
= 65537*someting + 3551*something_else
....
keep going until you get
....
1 = 65537*something + 3551*something_else
These ideas should get you started.

Best

Kai-Uwe Bux
Nov 1 '05 #8
toy
you are a LIFESAVER

thanks sooo much!

Nov 1 '05 #9
* Kai-Uwe Bux:

[relevant info, gcd]

These ideas should get you started.


Just tell me how you saw what he was trying to do?

Even if it's off-topic.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Nov 1 '05 #10
toy
@alf what do you mean?

I understood because I have prior knowledge and familiarity with
Euclid's algorithm..and his explanation was very clear and concise.

why do you ask?

Nov 1 '05 #11
Neo
"toy" <ta******@gmail.com> wrote in
news:11*********************@o13g2000cwo.googlegro ups.com:



Euclid's Algo?? Which one.?
Neo

--
Nov 1 '05 #12
Alf P. Steinbach wrote:
* Kai-Uwe Bux:

[relevant info, gcd]

These ideas should get you started.


Just tell me how you saw what he was trying to do?

Even if it's off-topic.


Easy: the following line from the original post gives it away:

I am trying to find integers where 65537i + 3551j = 1

What follows is code that clearly tries a brute force attack to find i and
j. After fixing, the relevant portion looks like so:

for (long i=0; i<65537; i++) {
for (long j=0; j<3511; j++) {
{
x=65337 * i + 3511 * j;
if (x==1) {
cout <<"i: "<< i << " j: "<< j<< endl;
}

}}

Best

Kai-Uwe Bux
Nov 1 '05 #13

Kai-Uwe Bux wrote:
Alf P. Steinbach wrote:
* Kai-Uwe Bux:

[relevant info, gcd]

These ideas should get you started.


Just tell me how you saw what he was trying to do?

Even if it's off-topic.


Easy: the following line from the original post gives it away:

I am trying to find integers where 65537i + 3551j = 1

What follows is code that clearly tries a brute force attack to find i and
j. After fixing, the relevant portion looks like so:

for (long i=0; i<65537; i++) {
for (long j=0; j<3511; j++) {
{
x=65337 * i + 3511 * j;
if (x==1) {
cout <<"i: "<< i << " j: "<< j<< endl;
}

}}


Don't you think he should include some negative integers as well, or he
might waste computer resources for nothing.

hint: neither (0,1) nor (1,0) doesn't work, so...

Nov 1 '05 #14
toy wrote:

@alf what do you mean?

I understood because I have prior knowledge and familiarity with
Euclid's algorithm..and his explanation was very clear and concise.

why do you ask?


I guess because this looks like a homework assignment in basic
loop handling. And for that, a teacher is not happy with a solution
based on euclids algorithm (probably because a newbie is not able
to write one on his own).

--
Karl Heinz Buchegger
kb******@gascad.at
Nov 2 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

38
by: jrlen balane | last post by:
basically what the code does is transmit data to a hardware and then receive data that the hardware will transmit. import serial import string import time from struct import * ser =...
17
by: savesdeday | last post by:
In my beginnning computer science class we were asked to translate a simple interest problem. We are expected to write an algorithm that gets values for the starting account balance B, annual...
5
by: Rob Somers | last post by:
Hey all I am writing a program to keep track of expenses and so on - it is not a school project, I am learning C as a hobby - At any rate, I am new to structs and reading and writing to files,...
3
by: kuiyuli | last post by:
I'm using VC++ .Net to do a simlple program. I tried to use <vector> <list> in the program, and I simply put the folowing lines " #include <list> #include <vector> #include <string> using...
2
by: Vitali Gontsharuk | last post by:
Hi! I have a problem programming a simple client-server game, which is called pingpong ;-) The final program will first be started as a server (nr. 2) and then as a client. The client then...
4
by: yogesh | last post by:
mysql in c++ initialize error occurs a simple program is executed in redhat9.0 , using gcc 3.2.2 compiler version ... #include <stdio.h> #include <mysql.h> #include <string.h> int main() {
5
by: Michael | last post by:
Hi All, I have three very simple files as below. When I try and compile these with g++ -ansi -Wall -pedantic -o crap Base.h Other.h I get an error: Base.h:7: internal compiler error:...
8
by: ftjonsson | last post by:
hello, I was wondering if anyone could tips me on what I am doing wrong when writing the following code: #include <iostream> using namespace std; int main () {
4
by: naveenpadmadas | last post by:
Hi, i have a simple query. I was practising a c program using function by just calling the function. The called function are defined with only printf statements. I tried executing the same program...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.