#include<iostream>
#include<math.h>
using namespace std;
int main()
{
long int t,n;
cin>>t;
while(t--)
{
cout<<"abc";
}
return 0;
}
i am getting run time error for t>10000.
how to solve it. range of t>1000000
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
long int t,n;
cin>>t;
while(t--)
{
cout<<"abc";
}
return 0;
}
i am getting run time error for t>10000.
how to solve it. range of t>1000000
SIGXFSZ means the process tried to write a file larger than the host allows — exactly what happens when the program prints "abc" once per test case for very large t. As already noted, the code is O(t) (not O(1)); heavy I/O is the bottleneck. Ideone (and some judges/tools) also enforce output-size and time limits, so a local build may run while the online tool gives SIGXFSZ or TLE.
For idiomatic, fast C++ I/O: disable synchronization with C stdio, untie cin, avoid std::endl (it flushes), and buffer output so the program performs far fewer write syscalls. The snippet below demonstrates the pattern (read, compute, append to one big string, then print once):
#include <iostream>
#include <string>
#include <cmath>
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
if (!(std::cin >> t)) return 0;
std::string out;
out.reserve((size_t)t * 4); // roughly: adjust to expected output length
while (t--) {
long long n;
std::cin >> n;
long long r = (long long)std::sqrt((double)n);
out += std::to_string(r);
out += '\n';
}
std::cout << out;
} Notes and cautions: reserving memory avoids repeated reallocations but can use a lot of RAM for huge outputs — if memory is a concern, flush in chunks (append ~10k lines then cout << chunk; chunk.clear()). Do not mix scanf/printf with cin/cout after calling sync_with_stdio(false). If an online judge still gives TLE after these I/O fixes, revisit the algorithm: minimize per-case work and verify the problem really requires printing for every test case.
Jump to Post— deceptikon 1,790What compiler and OS are you using? What's the runtime error?
Jump to Post— deceptikon 1,790Are you redirecting output to a file? SIGXFSZ is the signal raised when a file exceeds its size limitation.
What compiler and OS are you using? What's the runtime error?
Are you redirecting output to a file? SIGXFSZ is the signal raised when a file exceeds its size limitation.
actually there is a question on a website in which number of test cases are <1000000
i am submitting there. the site is giving me time limit exceeded.
my code complexity is O(1). so i tried it on ideone which gives me run time error.
i am submitting there. the site is giving me time limit exceeded.
Okay, that's completely different. Obviously if you're writing to cout over 10,000 times then it's going to take a while. That's the problem, and the root cause is that your code is too slow due to the overhead of output.
my code complexity is O(1).
No, your code complexity is O(t).
so i tried it on ideone which gives me run time error.
It's not unreasonable to assume that Ideone has stringent limits on things like this, so I'm not surprised at all that you got a SIGXFSZ error. Use a real compiler on your local machine and that error will vanish.
in my code i have to calculate just sqrt of input.
i tried scanf but it gives TLE too. so what should i do?
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.