### imtheonly1's blog

By imtheonly1, history, 6 days ago,

What mistake I'm Doing?

The python code is working fine but C++ doesn't.

PYTHON

N = 1000000000000000000
i = 2
c = 0
while 1 + i + i * i + i * i * i <= N:
temp = 1 + i + i * i + i * i * i
x = i * i * i
while temp <= N:
c += 1
x = x * i
temp = temp + x
i += 1
print(c)

# OUPTUT
# 1037545

# =====
# Used: 936 ms, 0 KB


CPP

// author: imtheonly1
// time: 2024-07-28 19:33:55
//
// Problem: E2. Rudolf and Snowflakes (hard version)
// URL: https://mirror.codeforces.com/contest/1846/problem/E2
// Time Limit: 2000 ms
//

#include <iostream>
#include <cmath>

int main() {
long long N = 1000000000000000000LL; // 1e18
long long i = 2;
long long c = 0;

while (1 + i + i * i + i * i * i <= N) {
long long temp = 1 + i + i * i + i * i * i;
long long x = i * i * i;

while (temp <= N) {
c++;
x = x * i;
temp = temp + x;
}

i++;
}

std::cout << c << std::endl;
return 0;
}

// OUTPUT
// Invocation failed [TIME_LIMIT_EXCEEDED]

// Runtime error: exit code is -1
// =====
// Used: 15000 ms, 0 KB


• 0

By imtheonly1, history, 8 months ago,

I am a Specialist.

Need help moving forward.

• +3