You are not logged in. Please login at to post your questions!


PRIME1: TLE on long long and AC on int

Using the same code, if I use the long long data type it shows TLE and if the data type ONLY is changed to int then it gets AC. Moreover, the constraints' values are not in the int range..

Problem: PRIME1
Solution: Using int AC
Solution: Using long long TLE

asked 07 Jan, 01:52

utsavsingh899's gravatar image

accept rate: 0%

edited 07 Jan, 20:02

the intended solution is segmented sieve. Using long long/int will not matter if you use that logic. Your brute solution with int just passed luckily :P

(08 Jan, 01:18) swetankmodi ♦♦6★

Which problem are you discussing, please share problem link.and your solution link to check the issue.(Provided that the problem should not be of any ongoing contest.)


answered 07 Jan, 04:20

gjaiswal108's gravatar image

accept rate: 0%

added the required links

(07 Jan, 20:04) utsavsingh8991★

Sometimes using operation like % on long long takes more time than on int numbers, because long long is 64 bit ,while int is 32 bit.

(07 Jan, 23:58) gjaiswal1084★

This doesn't usually happen, but only when the time limits are too strict and constraints quite high. There's higher chance of getting into such a problem when your code involves a lot of modulo operations and data structures (like sets) that involve operations of long integers in the comparator function, though the chance of running into TLE is low even then.

I usually use this #define int long long in the contest to save time

I have almost never encountered such issues (except during some practice problems on spoj, though the problems were intentionally designed so).


answered 08 Jan, 01:06

thefallenstar's gravatar image

accept rate: 0%

toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • 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:


question asked: 07 Jan, 01:52

question was seen: 163 times

last updated: 08 Jan, 01:18