913 - Joana and the Odd Numbers

All about problems in Volume IX. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Postby laicc86 » Thu Oct 25, 2007 6:58 pm

after i changed the function to
Code: Select all
long long odd_num(long long num)

the Verdict become CE...
i deleted the odd_num and type into main...
it become AC...
it seems like ACM doesn't accept function!? :o

and thx anyway Jan~ :D
laicc86
New poster
 
Posts: 5
Joined: Sun Oct 07, 2007 6:52 pm

Postby Jan » Thu Oct 25, 2007 10:28 pm

May be you have done something wrong in the prototype declaration.
Ami ekhono shopno dekhi...
HomePage
Jan
Guru
 
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh

need test cases.

Postby apurba » Fri Dec 07, 2007 10:35 pm

Code: Select all

deleted after accepted

Code: Select all
keep dreaming...
apurba
New poster
 
Posts: 42
Joined: Sun Oct 07, 2007 10:29 pm
Location: In Front of Computer

Re: 913 - Joana and the Odd Numbers

Postby sizogee » Tue Sep 09, 2008 10:24 pm

Getting TLE...

Code: Select all
#include <stdio.h>

int main(void) {
  long long x = 1;
  int done = 0;

  while (done != 1) {
    scanf("%ld", &x);
    if (x == 0)
      done = 1;
    else {
      x += 1;
      x /= 2;
      printf("%ld\n", (3 * ((2 * (x * x)) - 3)));
      }
  }
  return 0;
}


99999999 and 1000000001 both work. Entering a non-number value makes it go crazy, but this shouldn't be causing the error, right?
sizogee
New poster
 
Posts: 1
Joined: Tue Sep 09, 2008 10:20 pm

Re: 913 - Joana and the Odd Numbers

Postby tajbir2000 » Thu Jan 08, 2009 3:23 pm

Re: 913 - Joana and the Odd Numbers

Post by sizogee on Wed Sep 10, 2008 3:24 am
Getting TLE...



ur program is not breaking at EOF.Read problem stat. wil u get N=0?????

code>>like this >>>
while(scanf("%lld",&x)==1){
....................................
......................................
printf("%lld\n", (3 * ((2 * (x * x)) - 3)));
}

remember %lld>>>not %ld

i think now u will get AC :D
tajbir2000
New poster
 
Posts: 19
Joined: Fri Sep 05, 2008 6:39 pm
Location: bangladesh

913 - Joana and the Odd Numbers

Postby sazzadcsedu » Fri Jan 30, 2009 10:40 pm

run sample input.
but show wrong output for big number;
plz someone help.
whats wrong???

Code: Select all
 #include<stdio.h>


 int main()
{
  int n,m,p,num;
 long long sum_tot,sum_even,tot_sum,lst3_sum,lst_trm;
   while(scanf("%d",&num)==1)

{

    n=num-2;
   m=n-1;
   p=m/2;

 sum_tot=n*(n+1)/2;

sum_even=p*(p+1);
tot_sum=sum_tot-sum_even;
                 
 tot_sum*=2;
printf("%lld\n",tot_sum);
 lst_trm=(tot_sum+2*num)-1;   
               
lst3_sum=(3*lst_trm)-6;
printf("%lld\n",lst3_sum);
             

}
    return 0;
  }
sazzadcsedu
Experienced poster
 
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.

Re: 913 - Joana and the Odd Numbers

Postby newkid » Fri Jan 30, 2009 11:42 pm

@sazzadcsedu

change ur int variables to long long. n*(n+1)/2 will overflow if n is big..
hmm..
newkid
Learning poster
 
Posts: 73
Joined: Fri Dec 12, 2008 3:06 am

Re: 913 - Joana and the Odd Numbers

Postby sazzadcsedu » Fri Jan 30, 2009 11:48 pm

still wrong ans!!!
need more help.
sazzadcsedu
Experienced poster
 
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.

Re: 913 - Joana and the Odd Numbers

Postby newkid » Sat Jan 31, 2009 12:25 am

did you change this
1.
int n,m,p,num;
to
long long n,m,p,num;

2.
while(scanf("%d",&num)==1)
to
while(scanf("%lld",&num)==1)

3. comment the debug line..
printf("%lld\n",tot_sum);
to
//printf("%lld\n",tot_sum);

i am damn sure u didnt do one of this..
hmm..
newkid
Learning poster
 
Posts: 73
Joined: Fri Dec 12, 2008 3:06 am

Re: 913 - Joana and the Odd Numbers

Postby sazzadcsedu » Sat Jan 31, 2009 8:28 pm

yea. ur right.
i forgot to comment the debug line.
but main problem was--> rather than,
sum_tot=n*(n+1)/2;
it should be
sum_tot=(n*(n+1))/2;
however, u r realy a great man.
so dont forget to help me later.
sazzadcsedu
Experienced poster
 
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.

Re: 913 - Joana and the Odd Numbers

Postby newkid » Fri Feb 06, 2009 3:24 am

@sazzadcsedu
I think you should remove your code.

cheers
hmm..
newkid
Learning poster
 
Posts: 73
Joined: Fri Dec 12, 2008 3:06 am

Re: 913 - Joana and the Odd Numbers

Postby Bidhan » Mon May 17, 2010 5:10 pm

AC :)
Last edited by Bidhan on Sun Nov 21, 2010 9:22 pm, edited 1 time in total.
Bidhan
New poster
 
Posts: 6
Joined: Mon May 17, 2010 5:07 pm
Location: University Of Dhaka, Bangladesh.

Re: 913 - Joana and the Odd Numbers

Postby rebecca6212 » Sat Sep 18, 2010 5:11 pm

can anybody tell me what's wrong with the code?
thank you :)

Code: Select all
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int n,x,y;
    int N[63];
    int m;
   while(1){
    printf("n:");
    scanf("%d",&n);
        while(n%2==1){
            x=n/2;
            m=(1+(2*x)-1)*x+1;
            N[0]=m;
            //printf("m=%d\n",N[0]);
           
            for(int i=0;i<n;i++){
                N[i]=m+2*i;
               // printf("%d\t",N[i]);
                }
               
            break;
           
       
        }
        if(n%2==1){
       
        y=N[n-1]+N[n-2]+N[n-3];
        printf("%d",y);
        printf("\n");}
        else break;

        }
   
    system("PAUSE");
    return EXIT_SUCCESS;
}
rebecca6212
New poster
 
Posts: 1
Joined: Sat Sep 18, 2010 5:04 pm

Re: 913 - Joana and the Odd Numbers

Postby helloneo » Sat Sep 18, 2010 5:34 pm

rebecca6212 wrote:can anybody tell me what's wrong with the code?
thank you :)


The result may not fit in 32 bit integer..
Use unsigned long long..

Remove your code after AC :)
helloneo
Guru
 
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

913 - Joana and the Odd Numbers

Postby @mjad » Wed Apr 20, 2011 10:32 am

i am not understand how i can solve it?
write me algorithm, or give me short hints to solve this problem
@mjad
New poster
 
Posts: 44
Joined: Thu Jul 22, 2010 9:42 am

Previous

Return to Volume IX

Who is online

Users browsing this forum: No registered users and 1 guest

cron