## sumi1234's Profile User Rating:

Reputation: 0 Apprentice
Group:
Members
Active Posts:
30 (0.03 per day)
Joined:
07-November 11
Profile Views:
1,141
Last Active:
Aug 26 2013 11:50 AM
Currently:
Offline

### Previous Fields

Dream Kudos:
0
sumi1234 has not set their status

### Posts I've Made

1. #### In Topic: Getting segmentation fault in code to find a^b mod m on spoj

Posted 25 Aug 2013

jimblumberg, on 25 August 2013 - 01:52 PM, said:

Please explain the following line:

```        b[260] = {0};
```

There are a couple of things wrong but you need to tell me what you're trying to do before I can offer suggestions on a fix.

Jim

I was just checking to see if reinitialising the array to 0 might work. As I was getting a seg fault.

Basically, I am reading in t, which is the number of test cases.

For each test case , I take as input 3 numbers a , b and m where a and m are in base 10 and b is in base 3

I print a^b mod m for each test case

I have inputted b in the form of a c string .

convert function converts the c string b into bint in base 10.

calc function calculates (a^b-1 mod m)*a mod m.

so for the final result i do result%m again.

(ab) mod m = ((a mod m)*(b mod m))mod m

P.S. try using the ideone link. There was some problem while copy pasting so weird symbols like > are there in the program
2. #### In Topic: Getting segmentation fault in code to find a^b mod m on spoj

Posted 25 Aug 2013

jimblumberg, on 25 August 2013 - 01:21 PM, said:

I don't know how it is working at all. I get the following error when I try to compile your code:

Quote

main.c||In function ‘convert’:|
main.c|20|error: comparison between pointer and integer|

Jim

Sorry about that.. try this one
```#include<stdio.h>

long long calc(long a,long long b,long int m)
{
long long temp;
if(b==0)
return 1%m;
temp = calc(a%m,(b>>1),m);
if(b%2 == 0)
return (temp*temp)%m;
else
return ((a%m)*temp*temp);

}

long long convert(char arr[])
{
int i =0 ;
long long result = 0;
for (i=0;arr[i] != '\0';i++)
{
result = result*3 + (arr[i] - '0');
}
return result;
}
int main()
{
long int t,i,m;
long long bint;
scanf("%ld",&t);
long int a;//base 10
char b[260];
//char *endptr;
for(i=0;i<t;i++)
{
scanf("%ld",&a);
scanf("%s",B)/>;
scanf("%ld",&m);
bint = convert(B)/>;
b[260] = {0};
if(bint==0)
printf("%ld",1%m);
else if(bint == 1)
printf("%ld",a%m);
else
{
printf("%lld\n",(calc(a%m,bint,m))%m);
}

}
return 0;
}
```

Here is the ideone link for the same
http://ideone.com/BxkzQF
3. #### In Topic: First J2ee project

Posted 30 Oct 2012

fromTheSprawl, on 29 October 2012 - 07:32 PM, said:

Additional thoughts for you:
1. Have you considered what server to use? Your J2EE project will not run without a server you know.
2. Are you considering buying for proprietary software to run this thing(database, libraries) or are you planning to go the freeware way?
3. I'm sure there'll be some reports generation that will happen on your system. Have you decided what reports library to use?
4. Last of all, I'm just throwing this out there, but look into using frameworks like Spring and Hibernate. You can add this to your experience.

Good luck!

Greatly informative reply .
1. Well most probably gonna use tomcat apache or apache server
2. The database is gonna be sql server (We are getting it for free as i am a student ) or mysql

I have another question : a friend if mine said that if we have to deploy it on a LAN , how about making the web app using php and mysql as it will take less time. Thought??
4. #### In Topic: heap sort C implementation

Posted 13 Oct 2012

blackcompe, on 13 October 2012 - 03:25 PM, said:

Since I'm not quite convinced 10^6 elements should be creating a seg fault, I'm going to assume that (1) you're using Visual C++ which has a default stack size of 1MB or (2) you've got a programming error. You're using conio.h, so I know you're on a Windows machine. As a workaround you can create the array on the heap. As good practice, you shouldn't create large objects on the stack.

Creating the array on the heap solved the problem . Thanks
5. #### In Topic: heap sort C implementation

Posted 13 Oct 2012

I tried to run my program with
```unsigned int max_size = 1000000
```
(which is the array index) and I am getting a segmentation fault in my program(i think) (the problem remains even if i use
```std::size_t
```

so is there something wrong with my implementation?? I am only able to run upto a max array size of 100000 (which takes 47 ms to sort)

Member Title:
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

E-mail: