Good day, it's my first time doing something like this so I wanted to solve some of the challenges on project Euler, however I reached a block on my code, even before I submitted I was aware that I would be unable to compile within time limits for numbers well beyond the million or close to a million, still went along with it and of course, the test cases on the million(s)? [because they are hidden and I dont exactly know the numbers] expired due to time limits constraints.
I was wondering if I could receive some feedback on how to improve my code, given that at the minimum the value received would be a million of course.
class Solution {
private static void mathSolver(long _number){
long _sum = 0;
for(long x = 0; x<_number; x++){
if((x % 3 == 0) || (x % 5 == 0)){
_sum += x;
}
}
Console.WriteLine(_sum);
}
static void Main(String[] args) {
int t = Convert.ToInt32(Console.ReadLine());
for(int a0 = 0; a0 < t; a0++){
int n = Convert.ToInt32(Console.ReadLine());
mathSolver(n);
}
}
}
I already tried of tinkering with it with some math sequences, trying to figure out a pattern that would allow me to jump between numbers, so that instead of iterating through every number on a million, I would, lets say, jump between 3's or 5s directly, however no operation that I could think of would give me the result I wanted as it was very prone to mistakes along the way.
A slight background of me if anyone is interested while reviewing, I'm not exactly new to C#, been doing it for slightly under 2 years however my first employer procured tons of bad practices and code disasters, this is why I want to expose myself to these kind of things, to improve efficiency while coding, to get better code readibility and presentation as well as trying to find solutions that aren't as forceful.
Thank you for your answers and may you have a nice day!