×

runtime error in ALGPRX

 0 i'm getting runtime error(SIGSEV) in problem ALGPRX. Help me anyone. Here is my code. asked 30 Jul '14, 18:55 115●6●21 accept rate: 16%

 1 Since U<10^6, you have to assign memory outside main....Even then your code will not get accepted because ,,,it is too slow....for every test case ,,you are calculating all the prime nos upto 'U' .You are actually repeating the work already done. A more better approach would be , Declare bool array [10^6],long long int sum[10^6] outside main. Now using sieve of erastotehenes algo or any other good primality testing algo...update the bool array. If(i=prime)then bool[i]=true, else false. Now update the sum array..sum[i]=Sum of all primes less than i. Now for each test case you can easily read from the sum array and update the answer as sum[U]. This code time complexity would roughly be O(10^7+N),where N is the no of test cases, which will compile under the time limit easily..If you find this post helpful upvote and mark it as accepted answer...CHEERS HAPPY CODING :). answered 31 Jul '14, 11:47 3★prem_93 623●3●8●16 accept rate: 19%
 0 Upper bound for given input is U<10^6. Assign memory outside main(global scope). int prime[1000006]; int main() { //insert code here return 0; } answered 30 Jul '14, 22:45 333●2●3●9 accept rate: 20%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1

question asked: 30 Jul '14, 18:55

question was seen: 276 times

last updated: 31 Jul '14, 11:48