1049 - Sum
Forum rules
Remember that posting AC code is not allowed here. If you are going to ask a question or to post a solution, describe your algorithm instead. Posting AC code will be penalized.
Remember that posting AC code is not allowed here. If you are going to ask a question or to post a solution, describe your algorithm instead. Posting AC code will be penalized.
-
- Posts: 1
- Joined: 4 years ago
- Gender:
Re: 1049 - Sum
I was wondering if there's any chance this problem might be wrong when interpreting C# answers
I used the custom tool of the Datagen and used my code to compare my answers to the one that was suppose to be. I used different numbers and got it right but whenever I try to submit it it gives me a "Wrong answer" error.
http://imgur.com/bPdBVtv
I could submit my code but well I shouldn't.
I used the custom tool of the Datagen and used my code to compare my answers to the one that was suppose to be. I used different numbers and got it right but whenever I try to submit it it gives me a "Wrong answer" error.
http://imgur.com/bPdBVtv
I could submit my code but well I shouldn't.
- ymondelo20
- Posts: 1968
- Joined: 7 years ago
- Location: Universidad de las Ciencias Informáticas
- Gender:
- Contact:
Re: 1049 - Sum
You can post your code, because it´s not accepted.
"Every problem has a simple, fast and wrong solution" OJ's Main Law. 

Problem 1049
I tried this problem a few times, I always get the input and output right, but when I submit the problem in COJ it always judge the answer as wrong.
this is the my code:
#include<iostream>
using namespace std;
int main()
{
int n,sum = 0;
cin >> n;
for(int i = 1; i <= n; i++)
sum = sum + i;
cout << sum;
return 0;
}
I also tried the problem using this formula : (N(N+1))/2
and the same thing happens, The program gives me the right output but COJ still judge it as wrong answer.
Any tips on what I am doing wrong here?
this is the my code:
#include<iostream>
using namespace std;
int main()
{
int n,sum = 0;
cin >> n;
for(int i = 1; i <= n; i++)
sum = sum + i;
cout << sum;
return 0;
}
I also tried the problem using this formula : (N(N+1))/2
and the same thing happens, The program gives me the right output but COJ still judge it as wrong answer.
Any tips on what I am doing wrong here?
-
- Posts: 97
- Joined: 4 years ago
- Gender:
Re: 1049 - Sum
Hello Pedro. Threads have been created for each exercise ahead of time. This makes it so that exercises on COJ can have links to their respective threads on the forums. I've merged your post into the correct thread since there is no need to create a new one.
Regarding your problem, you may want to read the wording of the exercise very carefully. Does your program give the correct output for all possibles values of N?
Regarding your problem, you may want to read the wording of the exercise very carefully. Does your program give the correct output for all possibles values of N?
- ymondelo20
- Posts: 1968
- Joined: 7 years ago
- Location: Universidad de las Ciencias Informáticas
- Gender:
- Contact:
Re: 1049 - Sum
Haaa ... common mistake...
You will punish yourself at the end.
You will punish yourself at the end.
"Every problem has a simple, fast and wrong solution" OJ's Main Law. 

Re: 1049 - Sum
@Pedro Men, you have to do a slowly read for this problem, that formula is not completely right for this problem.
This is a little help from Matanzas city.
JoseA132
This is a little help from Matanzas city.
JoseA132



Re: 1049 - Sum
Hi fellows, first, I just use the formula (N*(N+1)/2), then, I read carefully and realize that all numbers don't fix in it, so, i made small "adjustment" for those several cases. I am still getting "Wrong answer" from the site, I really need help 
Thanks in advance

Thanks in advance
Re: 1049 - Sum
@chicha estuve mirando tu solución y el "ajuste" que le hiciste realmente no resuelve el problema pues la suma es de todos los números desde 1 hasta n
teruel