system
October 13, 2018, 12:16pm
1
We all know that phi(n) is the number of coprimes of n which are smaller than n. In this problem you…
Click here to read the complete problem statement.
If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.
#include<stdio.h>
int main()
{
int N, i, sum1=0, sum2=0;
scanf("%d", &N);
for(i=1;i<=N;i+=2){
sum1+=i;
}
for(i=2;i<=N;i+=2){
sum2+=i;
}
printf("%d", (sum1-sum2));
return 0;
}
where is my mistake??
hjr265
October 17, 2018, 9:43am
3
N can be as large as 10^18. You cannot store such a large number in an int
.
#include < iostream >
int main()
{
long long N; // i also tried with int type
std::cin >> N;
if(N % 2 == 0) {
std::cout << -N / 2 << std::endl;
}
else {
std::cout << (N + 1) / 2 << std::endl;
}
return 0;
}
// I can’t find the wrong. what’s the mistake. Is my algorithm wrong? Need help.
hjr265
October 17, 2018, 3:17pm
5
Why is there a minus sign?
if N is even , the result would be negative…result = (summation of odd numbers till N) - (summation of even number till N)
okk…my code is accepted . There shouldn’t be the minus sign . Thank you very much for this suggestion. I couldn’t understand the problem clearly. Thank you again.
whats wrong here?
#include<stdio.h>
int main()
{
int N,i,sum1=0,sum2=0;
scanf("%d",&N);
for(i=1;i<=N;i++)
{
if(i%2==1)
sum1=i+sum1;
else
sum2=i+sum2;
}
if(N%2==1)
{printf("%d",sum1-sum2);}
else
{printf("%d",sum2-sum1);}
return 0;
}
hjr265
October 17, 2018, 4:59pm
11
Try testing your code with the input 10000000000
.
Nuhin3
October 17, 2018, 6:26pm
12
a=int(input("Enter the value of N: ")
if N%2==0:
print("Even Number")
else:
print("Odd Number")
Nuhin3
October 18, 2018, 9:10am
13
input N
if N%3==0:
print(“This is a Odd Number”)
else:
print(“This is a Even Number”)
Why I am getting compilation error?
hjr265
October 18, 2018, 4:44pm
15
Please share your submission ID.
#include <stdio.h>
void main()
{
int i, N, odd= 0, even= 0,res=0;
0<=N<=10^18;
scanf("%d", &N);
for (i = 1; i <= N; i++)
{
if (i % 2 == 0)
even = even + i;
else
odd = odd + i;
}
res=odd-even;
printf("%d\n", res);
}
whats wrong with the code?
So basically my problem is that the answer it gives seems to be correct, but after submitting it I get a message saying wrong answer. My code is:
#include <stdio.h>
int main()
{
long long N, sum1=0, sum2=0;
scanf("%I64d", &N);
while(N>=0)
{
sum1=sum1+N;
N--;
sum2=sum2+N;
N--;
}
if(sum1>sum2)
{
printf("%I64d\n", sum1-sum2);
}
else
{
printf("%I64d\n", sum2-sum1);
}
return 0;
}
md_moon
October 20, 2018, 1:32pm
18
#include<stdio.h>
int main()
{
long long int a,sum,sum1,sum2,sum3,even;
scanf("%lld",&a);
if(a%2==0)
{
sum1=(a*(a+1))/2;
even=a/2;
sum2=even*(even+1);
sum3=sum1-sum2;
sum=sum2-sum3;
}
else
{
sum1=(a*(a+1))/2;
even=(a-1)/2;
sum2=even*(even+1);
sum3=sum1-sum2;
sum=sum3-sum2;
}
printf("%lld",sum);
return 0;
}
Where is the problem in this code!!!
#include<stdio.h>
int main()
{
long long i,sum1=0,sum2=0,n,n1,n2;
scanf("%lld",&n);
if(n%2==1){
n1=(n-1)/2+1;
sum1=(n1*(2+(n1-1)*2))/2;
sum2=((n1-1)*(4+(n1-2)*2))/2;
printf("%lld",sum1-sum2);
}
else{
n2=(n-2)/2+1;
sum1=((n2-1)*(2+(n2-2)*2))/2;
sum2=(n2*(4+(n2-1)*2))/2;
printf("%lld",sum2-sum1);
}
return 0;
}
#include<stdio.h>
#include<conio.h>
main()
{
int A;
printf("Enter the value");
scanf("%d",&A);
if(A%2==0)
printf("%d is the even",A);
else
printf("%d is the odd",A);
getch();
}
showkat
October 21, 2018, 4:56am
21
why wrong answer?
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int n,sumOfEven,sumOfOdd,result=0;
while(1==scanf("%d",&n))
{
sumOfEven=0;
sumOfOdd=0;
for(int i=0; i<=n; i++)
{
if(i%2==0)
{
sumOfEven+=i;
}
else
{
sumOfOdd+=i;
}
}
result=abs(sumOfEven-sumOfOdd);
cout<<result<<endl;
}
return 0;
}