Daily Archives

Articles indexed Saturday May 29 2010

Page 17/76 | < Previous Page | 13 14 15 16 17 18 19 20 21 22 23 24  | Next Page >

  • Help making this code run faster for spoj.

    - by Josh Meredith
    I've been doing a few of the challenges on the Sphere Online Judge, but I can't seem to get the second problem (the prime generator) to run within the time limit. Does anyone have any tips for increasing the speed of the following code? #include <stdio.h> #include <math.h> int is_prime(int n); void make_sieve(); void fast_prime(int n); int primes[16000]; int main() { int nlines; int m, n; make_sieve(); scanf("%d", &nlines); for (; nlines >= 1; nlines--) { scanf("%d %d", &m, &n); if (!(m % 2)) { m++; } for ( ; m < n; m+=2) { fast_prime(m); } printf("\n"); } return 0; } /* Prints a number if it's prime. */ inline void fast_prime(int n) { int j; for (int i = 0; ((j = primes[i]) > -1); i++) { if (!(n % j)) { return; } } printf("%d\n", n); } /* Create an array listing prime numbers. */ void make_sieve() { int j = 0; for (int i = 0; i < 16000; i++) { primes[i] = -1; } for (int i = 2; i < 32000; i++) { if (i % 2) { if (is_prime(i)) { primes[j] = i; j++; } } } return; } /* Test if a number is prime. Return 1 if prime. Return 0 if not. */ int is_prime(int n) { int rootofn; rootofn = sqrt(n); if ((n <= 2) || (n == 3) || (n == 5) || (n == 7)) { return 1; } if (((n % 2) == 0) || ((n % 3) == 0) || ((n % 5) == 0) || ((n % 7) == 0)) { return 0; } for (int i = 11; i < rootofn; i += 2) { if ((n % i) == 0) { return 0; } } return 1; }

    Read the article

  • Why does Perl complain about "Unsuccessful stat on filename containing newline"?

    - by Daniel
    Hello, I am getting an error I do not understand. I am using File:Find to recurse a fylesystem on Windows using Activestate Perl 5.8.8 and trying to stat $File::Find::name; so I am not stat-ing a filename got from a text file scanning requiring chomp-ing or newline removing. I was unable to get file modification time, the mtime in: my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($File::Find::name); so trying a -s $File::Find::name gives me the error: Unsuccessful stat on filename containing newline A typical file name found is F01-01-10 Num 0-00000.pdf but I get the same error even renaming in E02.pdf

    Read the article

  • Slideshow from excel file listing the caption, sound file and image file?

    - by Slabo
    Hello, I have excel files with the following header: Caption Sound: Location of sound file Image: Location of image file How can I make a slideshow from this? Each slide should show image, caption, and play sound automatically according to the excel list. I don't care what software I use, if I can get the job done. Total slides ~10,000. In case interested,this is review material for English second language students. Any help appreciated, Thanks

    Read the article

  • How to get TinyMCE and Jquery validate to work together?

    - by chobo2
    Hi I am using jquery validate and the jquery version of tinymce. I found this piece of code that makes tinymce to validate itself every time something changes in it. Hi I am using the jquery validate with my jquery tinymce so I have this in my code // update validation status on change onchange_callback: function (editor) { tinyMCE.triggerSave(); $("#" + editor.id).valid(); }, This works however there is one problem. If a user copies something from word it brings all that junk styling with it what is usually over 50,000 characters. This is way over my amount of characters a user is allowed to type in. So my jquery validation method goes off telling me that they went over the limit. In the mean time though tinymce has cleaned up that mess and it could be possible now the user has not gone over the limit. Yet the message is still there. So is there a better function call I can put this in? Maybe tell tinymce to delay the valid when a paste is happening, or maybe a different callback? Anyone got any ideas?

    Read the article

  • SWT on Windows 64-bit

    - by Palani
    My application throws the exception below. Exception in thread "main" java.lang.UnsatisfiedLinkError: Cannot load 32-bit SW T libraries on 64-bit JVM. How to solve this? What is the name of jar file needed?

    Read the article

  • Thoughts/Input about Database Design for a CMS

    - by dallasclark
    I'm just about to expand the functionality of our own CMS but was thinking of restructuring the database to make it simpler to add/edit data types and values. Currently, the CMS is quite flat - the CMS requires a field in the database for every type of stored value (manually created). The first option that comes to mind is simply a table which keeps the data types (ie: Address 1, Suburb, Email Address etc) and another table which holds values for each of these data types. Just like how Wordpress keeps values in the 'options' table, PHP serialize would be used to store an array of values. The second option is how Drupal works, the CMS creates tables for every data type. Unlike Wordpress, this can be a bit of an overkill but really useful for SQL queries when ordering and grouping by a particular value. What's everyone's thoughts?

    Read the article

  • win32 sdk: how to make the caption/border of a child window transparent

    - by Eric
    I'm creating a child window within the main window. I assigned these styles to the child window: WS_CHILDWINDOW | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | WS_SIZEBOX | WS_CAPTION The child window I get has a caption and a resizable border. However there's no close button in the caption, and the caption/border of the child window is not transparent (I'm using the aero theme in windows 7). Here is the screen snap: How to add close button to the caption? How can I make the caption/border transparent?

    Read the article

  • Is it practical to build a web site using strict XHTML and relying on CSS 100% for visual style?

    - by Micah
    I tend to take the academic approach all too often and adhere to strict principles in my development when the reality is that I could have finished the project sooner had I been a little less cautious. I'm looking to find the right amount of practicality. I want to take the "Zen" approach to designing a site which (in my words) says "Use HTML strictly for content structure, and let the CSS magic do the rest". How practical is this in reality? One of the issues I run into is that I want to develop (make functional) the site first, then come back in and design it later. I know structure-wise how I want the site to flow, but I haven't even begun playing with the CSS layout, graphics, or any of the other designy stuff. What is the right approach here?

    Read the article

  • Contact picker with search function

    - by tiex
    This question1 describes a way how to show list of phone numbers and select one of them if my app needs a phone number. But image if I have a huge contact list, it is not enough to just show list but possibility for filtering (by contact's name) is also needed. Is there a standard way to show phones list with picking possibility and with filtering possibility? (I wouldn't like to invent my own) Is there a solution for the problem for sdk 2.0 and lower?

    Read the article

  • Need help on how to setup my packages and projects in eclipse

    - by jax
    I am new to Java and am making a license generator. This is my current setup. com.example.licensegenerator.client (used by the client application) :LicenseLoader (no Main method) :LicenseDownloader (no Main method) com.example.licensegenerator.server.keys (used by the server) :ProductKeyGenerator(Main method) com.example.licensegenerator.server.license (used on the server also) :LicenseGenerator(Main method) com.example.licensegenerator.lib (Shared classes between client and server) :Contants (no main) Now I have a few questions. Is it OK to have multiple Main() methods in a single project? Will I be able to compile them to different .jar files? (In this case I need two different jars for the server) Is there a better way to setup the packages? And a totally unrelated question, with exceptions, is it better to handle them right then and there or throw them and let the main method catch them all (the program cannot recover if an error occurs)

    Read the article

  • How to handle images better in Android

    - by primal
    In the microblogging application I am developing I wish to show an user image beside each post in the timeline. The images are small in size(max 50*50 dip) and are not more than 10 in number. I've two approaches in my mind. 1) Allow user to chose an image from Gallery on signing up. Send the image to the server and on subsequent signups load the image from the server. I'm worried whether this approach is doing too much unnecessary work. 2) The same method is same as above in first step but this time the image is not send to the server but a key value associated with the image is sent to the server. On subsequent signups, after obtaining the key from the server the specific image is loaded from gallery. I am not sure whether the second approach is possible. Any corrections on this aspect would be much appreciated. Also, Is it possible to store an image in SharedPreferences? Any new approach to handle this problem better are welcome.

    Read the article

  • Foreign key refering to primary keys across multiple tables?

    - by sanjay bharkatiya
    hi , i have three tables say city,state and road 1) city - city_id(PK),name 2) state- Stt_id(PK),name 3) Road- Edge_id(PK), Admin_id(FK) where Admin_id refers to city_id and Stt_id both. This is done because the tables are too huge. say city_id contains 1,2,3 and Stt_id contains 4,5,6 now if i am inserting 1,2,3,4,5,6 in admin_id it is throuing an error .. what is the solution of my problem, regards sanjay

    Read the article

  • ¿Que riesgo hay en usar extract con las variables superglobales de php?

    - by Carlos Montalvo
    Hola usando estas funciones, que riesgo corro en tener problemas de seguridad, es necesesario usar extract() o hay alguna manera mejor de convertir las variables superglobales (array) en trozos de variables. if ( get_magic_quotes_gpc() ) { $_GET = stripslashes( $_GET ); $_POST =stripslashes( $_POST ); } function vars_globals($value = '') { if (is_array ( $value )) $r = &$value; else parse_str ( $value, $r ); return $r; } $r = vars_globals( $_GET ); extract($r, EXTR_SKIP);

    Read the article

  • Flash Hates Me. Error #1009: Cannot access a property or method of a null object reference

    - by sol
    I simply create a movie clip, put it on the stage and give it an instance name of char. Here's my document class, simple as can be: public class Test extends MovieClip { public function Test() { char.x = 1315; char.y = 459; addEventListener(Event.ENTER_FRAME, mouseListen); } private function mouseListen(e:Event) { char.x = mouseX; char.y = mouseY; } } And I get this error: TypeError: Error #1009: Cannot access a property or method of a null object reference. at com.me::Test/::mouseListen() How in the world is it possible that it knows what "char" is in the constructor but not in the mouseListen function? What else could it be?

    Read the article

  • Getter and Setter - POJO object - Problem with input data in Struts2

    - by andreimladin
    I have a problem with setter and getter method in struts2. I have a form : ... + all input fields of job/ and action: (addJob is mapped at this action) public class InsertJobAction extends ActionSupport{ ... private Job job = null; public String execute(){ jobService.insert(job); //here job is not null; that is ok } getter and setter for job } this action works correctly; I have a similar form and action, but the input fields from thisform are less than first form; The problem is here: in execute() of the second action job is null. Why?? Does depend it of fields noumber ?? I have 2 constructors in my Job class one with no params, and one with all params for every field of class; I made debug with Log4j ...and in first case there arrives in Job constructor in the second not. Why??When it calls constructor??? When are called the setter and getter methodsb, before or after execute() method??? And when i have a form with input data?? Are called setter methods before execute() method? I'm very confusely because in a case it works without problems, but in the second case it doesn't Thanks, Andrew

    Read the article

  • C language preprocessor behavior

    - by khanna_param
    There are different kind of macros in C language, nested macro is one of them. Considering a program with the following macro #define HYPE(x,y) (SQUR(x)+SQUR(y)) #define SQUR(x) (x*x) Using this we can successfully compile to get the result. As we all know the C preprocessor replaces all the occurrence of the identifiers with the replacement-string. Considering the above example I would like to know how many times the C preprocessor traverses the program to replace the macro with the replacement values. I assume it cannot be done in one go.

    Read the article

< Previous Page | 13 14 15 16 17 18 19 20 21 22 23 24  | Next Page >