Thread: Seriously Whats wrong with my code

  1. #1
    Registered User
    Join Date
    May 2015
    Posts
    2

    Seriously Whats wrong with my code

    I am trying to solve a Problem code: LASTDIG2 in SPOJ SPOJ.com - Problem LASTDIG2
    but every time i am getting 'WA': Wrong Answer
    I have tried every posible Test Cases.I've written the code mentioned below.Please help
    Code:
    #include <stdio.h>
    int main() {
         int t;
        scanf("%d",&t);
        while(t--)
        {
         signed long long int b,c;
            scanf("%llu %llu",&b,&c);
            b=b%10;
                if((c==0)&& (b!=0))  printf("%d\n",1);
                else
                {
                        if((c%4)==0)
                        printf("%d\n",((int)pow(b,4))%10);
                        else
                        printf("%d\n",((int)pow(b,c%4))%10);
                }
    
    
    
        }
        return 0;
    }

    When i googled for the solution i found the below code and the below mentioned code is 'Acepted' by Spoj:

    Code:
    #include<stdio.h>
    #include<string.h>
    int main()
    {
    char str[1005];
    unsigned long long int b,a,ans,len,t;
    scanf("%llu",&t); 
    while(t--){
    scanf("%s",str);
    scanf("%llu",&b);
     len=strlen(str);
    a=str[len-1]-'0'; 
    if(b==0&&a!=0) ans=1; 
    else{
    if(a==0){ ans=0; goto end;}
    if(a==5) {ans=5; goto end;}
    switch(b%4){
    case 0: ans=a%2!=0? 1:6;
    break;
    case 1: ans=a;
    break;
    case 2: ans=a*a%10;
    break;
    default : ans=a*a*a%10;
    break; 
    }
    }
    end :
    printf("%llu\n",ans);
    }
    return 0;
    }

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    You seem to miss something, and that probably that in what the problem wants you to do("a^b"), "a" will be far bigger than what a "long long" can support.
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    May 2015
    Posts
    2
    Quote Originally Posted by GReaper View Post
    You seem to miss something, and that probably that in what the problem wants you to do("a^b"), "a" will be far bigger than what a "long long" can support.
    The problem mentions that range of a should be 1<=a<=1000

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by iamsethi View Post
    The problem mentions that range of a should be 1<=a<=1000
    Wrong it means a can have 1 to 1000 digits in it.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    Quote Originally Posted by iamsethi View Post
    The problem mentions that range of a should be 1<=a<=1000
    Wrong it means a can have 1 to 1000 digits in it.
    You could treat the digits as 8-bit characters and hold them in an array as the code you got from the interwebs does.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 10-31-2011, 01:45 AM
  2. whats wrong with this code?
    By smahdi1991 in forum C Programming
    Replies: 18
    Last Post: 11-01-2009, 11:12 AM
  3. whats wrong with this code??
    By stehigs321 in forum C Programming
    Replies: 2
    Last Post: 10-29-2003, 11:00 PM
  4. whats wrong with this code i have?
    By stehigs321 in forum Game Programming
    Replies: 1
    Last Post: 10-29-2003, 08:38 PM
  5. whats wrong with this code
    By omalleys in forum C Programming
    Replies: 3
    Last Post: 06-20-2002, 03:13 PM