10515 - Powers Et Al.

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

Moderator: Board moderators

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Re: 10515 - Power et al.

Post by sohel »

abid_iut wrote:I think this code is giving correct output for every input is the board
Not quite!

Try this input:
2 100

The output is NOT 1. :)
abid_iut
Learning poster
Posts: 82
Joined: Wed Jul 16, 2008 7:34 am

Re: 10515 - Power et al.

Post by abid_iut »

Can U please tell me NOW what's the problem?
its showing WA
the code:

Code: Select all

Removed
is those value for n=0 is correct?
pls help :(
Last edited by abid_iut on Sat Dec 27, 2008 12:05 pm, edited 1 time in total.
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 10515 - Power et al.

Post by Obaida »

how it can be correct!!!! :o
We know that m^0 = 1;
So what ever is m if the power is 0 then the result will be 1.
try_try_try_try_&&&_try@try.com
This may be the address of success.
abid_iut
Learning poster
Posts: 82
Joined: Wed Jul 16, 2008 7:34 am

Re: 10515 - Power et al.

Post by abid_iut »

I think in this problem I have to take the last digit of M and last two digit of N.
Now If my consideration is correct than what is the output for the input

2 100

pls reply
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 10515 - Power et al.

Post by Obaida »

I tested all the case but still WA!!!!

Code: Select all

removed
Last edited by Obaida on Sat Dec 27, 2008 12:00 pm, edited 1 time in total.
try_try_try_try_&&&_try@try.com
This may be the address of success.
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Re: 10515 - Power et al.

Post by sohel »

abid_iut wrote:I think in this problem I have to take the last digit of M and last two digit of N.
Now If my consideration is correct than what is the output for the input

2 100

pls reply
According to calc.exe in windows: 2^100 = 1267650600228229401496703205376

So, the output for (2 100) is 6.

Ya, it's correct that you have to consider the last digit of M and last 2 digits of N. However, if last 2 digits of N = 00, then you have to convert it to N = 04.
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 10515 - Power et al.

Post by Obaida »

So many thanks to you.
At least it gave me Accepted. :)
Now i understand that why if the two digit of n are 0 then it will be divisible by 4 which is the highest chain value. So when i have 2 zero then i will take the highest chain length. Less then this it also accepts who's chain length is 2. And here no ones chain length is 3.
try_try_try_try_&&&_try@try.com
This may be the address of success.
abid_iut
Learning poster
Posts: 82
Joined: Wed Jul 16, 2008 7:34 am

Re: 10515 - Power et al.

Post by abid_iut »

Hey pleaseee someone help me.
this problem is making me crazy
is there any special I/O am I missing?
here is the code:

Code: Select all

Removed after AC

pls help :(
Last edited by abid_iut on Sat Dec 27, 2008 8:33 pm, edited 1 time in total.
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 10515 - Power et al.

Post by Obaida »

Check this case:
Input:

Code: Select all

24068 79330
0 0
Output:

Code: Select all

4
try_try_try_try_&&&_try@try.com
This may be the address of success.
abid_iut
Learning poster
Posts: 82
Joined: Wed Jul 16, 2008 7:34 am

Re: 10515 - Power et al.

Post by abid_iut »

Thanks
At last got AC :P
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/
lollyssium
New poster
Posts: 1
Joined: Thu May 27, 2010 6:12 pm

Re: 10515 - Power et al.

Post by lollyssium »

Code: Select all

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main ()
{
	unsigned long l,s,q,t,n,c,i;
	char x[2000],y[2000];
	while (1)
	{
		q=0;
		t=0;
		l=0;
		n=0;
		c=0;
		scanf("%s%s",x,y);
		l=strlen(x)-1;
		s=x[l];
		c=atoi(y);
		for (i=1;i<=2;i++)
		{
			if (i==1)
			{
				n=c%10;
				q=q+n;
				c=c/10;
			}
			else
			{
				n=c%10;
				n=n*10;
				q=q+n;
			}
		}
	
	if ((x[0]=='0') && (y[0]=='0'))
			break;
		if (x[0]=='0')
		{
			printf ("0\n");
			continue;
		}
		if (y[0]=='0')
		{
			printf ("1\n");
			continue;
		}
		if (s=='0')
		{
			printf ("0\n");
			continue;
		}
		if (s=='1')
		{
			printf ("1\n");
			continue;
		}
		if (s=='2')
		{
			if (q%4==0)
			{
				printf ("6\n");
				continue;
			}
			if (q%4==1)
			{
				printf ("2\n");
				continue;
			}
			if (q%4==2)
			{
				printf ("4\n");
				continue;
			}
			if (q%4==3)
			{
				printf ("8\n");
				continue;
			}
		}
		if (s=='6')
		{
			printf ("6\n");
			continue;
		}
		
		if (s=='3')
		{
			if (q%4==0)
			{
				printf ("1\n");
				continue;
			}
			if (q%4==1)
			{
				printf ("3\n");
				continue;
			}
			if (q%4==2)
			{
				printf ("9\n");
				continue;
			}
			if (q%4==3)
			{
				printf ("7\n");
				continue;
			}
		}
		if (s=='4')
		{
			if (q%2==0)
			{
				printf ("6\n");
				continue;
			}

			else 
			{
				printf ("4\n");
				continue;
			}
		}
		if (s=='5')
		{
			printf ("5\n");
			continue;
		}

		if (s=='8')
		{
			if (q%4==0)
			{
				printf ("6\n");
				continue;
			}
			if (q%4==1)
			{
				printf ("8\n");
				continue;
			}
			if (q%4==2)
			{
				printf ("4\n");
				continue;
			}
			if (q%4==3)
			{
				printf ("2\n");
				continue;
			}
		}
		
		
		if (s=='9')
		{
			if (q%2==0)
			{
				printf ("1\n");
				continue;
			}

			else 
			{
				printf ("9\n");
				continue;
			}
		}

			
		if (s=='7')
		{
			if (q%4==0)
			{
				printf ("1\n");
				continue;
			}
			if (q%4==1)
			{
				printf ("7\n");
				continue;
			}
			if (q%4==2)
			{
				printf ("9\n");
				continue;
			}
			if (q%4==3)
			{
				printf ("3\n");
				continue;
			}
		}

	}
	return 0;
}



what's wrong here?? I've checked all the test cases :( !! But still WA
blackcloud1971
New poster
Posts: 4
Joined: Wed Nov 04, 2009 7:52 pm

Re: 10515 - Power et al.

Post by blackcloud1971 »

How to delete a post????
Last edited by blackcloud1971 on Tue Jun 08, 2010 8:59 pm, edited 1 time in total.
blackcloud1971
New poster
Posts: 4
Joined: Wed Nov 04, 2009 7:52 pm

Re: 10515 - Power et al.

Post by blackcloud1971 »

Code: Select all

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    int main ()
    {
       unsigned long l,s,q,t,n,c,i;
       char x[2000],y[2000];
       while (1)
       {
          q=0;
          t=0;
          l=0;
          n=0;
          c=0;
          scanf("%s%s",x,y);
          l=strlen(x)-1;
          s=x[l];
          c=atoi(y);
          for (i=1;i<=2;i++)
          {
             if (i==1)
             {
                n=c%10;
                q=q+n;
                c=c/10;
             }
             else
             {
                n=c%10;
                n=n*10;
                q=q+n;
             }
          }
       
       if ((x[0]=='0') && (y[0]=='0'))
             break;
          if (x[0]=='0')
          {
             printf ("0\n");
             continue;
          }
          if (y[0]=='0')
          {
             printf ("1\n");
             continue;
          }
          if (s=='0')
          {
             printf ("0\n");
             continue;
          }
          if (s=='1')
          {
             printf ("1\n");
             continue;
          }
          if (s=='2')
          {
             if (q%4==0)
             {
                printf ("6\n");
                continue;
             }
             if (q%4==1)
             {
                printf ("2\n");
                continue;
             }
             if (q%4==2)
             {
                printf ("4\n");
                continue;
             }
             if (q%4==3)
             {
                printf ("8\n");
                continue;
             }
          }
          if (s=='6')
          {
             printf ("6\n");
             continue;
          }
          
          if (s=='3')
          {
             if (q%4==0)
             {
                printf ("1\n");
                continue;
             }
             if (q%4==1)
             {
                printf ("3\n");
                continue;
             }
             if (q%4==2)
             {
                printf ("9\n");
                continue;
             }
             if (q%4==3)
             {
                printf ("7\n");
                continue;
             }
          }
          if (s=='4')
          {
             if (q%2==0)
             {
                printf ("6\n");
                continue;
             }

             else
             {
                printf ("4\n");
                continue;
             }
          }
          if (s=='5')
          {
             printf ("5\n");
             continue;
          }

          if (s=='8')
          {
             if (q%4==0)
             {
                printf ("6\n");
                continue;
             }
             if (q%4==1)
             {
                printf ("8\n");
                continue;
             }
             if (q%4==2)
             {
                printf ("4\n");
                continue;
             }
             if (q%4==3)
             {
                printf ("2\n");
                continue;
             }
          }
          
          
          if (s=='9')
          {
             if (q%2==0)
             {
                printf ("1\n");
                continue;
             }

             else
             {
                printf ("9\n");
                continue;
             }
          }

             
          if (s=='7')
          {
             if (q%4==0)
             {
                printf ("1\n");
                continue;
             }
             if (q%4==1)
             {
                printf ("7\n");
                continue;
             }
             if (q%4==2)
             {
                printf ("9\n");
                continue;
             }
             if (q%4==3)
             {
                printf ("3\n");
                continue;
             }
          }

       }
       return 0;
    }
sorry dude :-? I made a mistake.... its fine for large input..... but the prob is u r using "atoi()". so it is converting a number from double to integer..... though luckily it solves all the input. but i think for some input it will definitely cause prob.....

SORRY AGAIN FOR THE PREVIOUS ANSWER.......I GAVE A WRONG ANSWER TO THAT PROBLEM...... AND THANK YOU....as ur response helped me to get Accepted. i m trying to delete my previous post.......SORRY AGAIN
LegendMaker
New poster
Posts: 2
Joined: Wed Oct 12, 2011 7:40 am

Re: 10515 - Power et al.

Post by LegendMaker »

Why TLE?

Code: Select all

import java.math.*;
import java.util.*;
public class Main
{
	public static void main(String[] args)
	{
		Scanner in=new Scanner(System.in);
		BigInteger a,b,c;
		c=BigInteger.TEN;
		while(in.hasNext())
		{
			a=in.nextBigInteger();
			b=in.nextBigInteger();
			if(a.compareTo(BigInteger.ZERO)==0&&b.compareTo(BigInteger.ZERO)==0)
				break;
			if(b.compareTo(BigInteger.ZERO)==0)
			{
				System.out.println(1);
				continue;
			}
			if(a.compareTo(BigInteger.ZERO)==0)
			{
				System.out.println(0);
				continue;
			}
			a=a.mod(c);
			if(a.compareTo(BigInteger.valueOf(1))==0)
				System.out.println(1);
			else if(a.compareTo(BigInteger.valueOf(2))==0)
			{
				b=b.mod(BigInteger.valueOf(4));
				if(b.compareTo(BigInteger.valueOf(1))==0)
					System.out.println(2);
				else if(b.compareTo(BigInteger.valueOf(2))==0)
					System.out.println(4);
				else if(b.compareTo(BigInteger.valueOf(3))==0)
					System.out.println(8);
				else if(b.compareTo(BigInteger.valueOf(0))==0)
					System.out.println(6);
			}
			else if(a.compareTo(BigInteger.valueOf(3))==0)
			{
				b=b.mod(BigInteger.valueOf(4));
				if(b.compareTo(BigInteger.valueOf(1))==0)
					System.out.println(3);
				else if(b.compareTo(BigInteger.valueOf(2))==0)
					System.out.println(9);
				else if(b.compareTo(BigInteger.valueOf(3))==0)
					System.out.println(7);
				else if(b.compareTo(BigInteger.valueOf(0))==0)
					System.out.println(1);
			}
			else if(a.compareTo(BigInteger.valueOf(4))==0)
			{
				b=b.mod(BigInteger.valueOf(4));
				if(b.compareTo(BigInteger.valueOf(1))==0)
					System.out.println(4);
				else
					System.out.println(6);
			}
			else if(a.compareTo(BigInteger.valueOf(5))==0)
				System.out.println(5);
			else if(a.compareTo(BigInteger.valueOf(6))==0)
				System.out.println(6);
			else if(a.compareTo(BigInteger.valueOf(7))==0)
			{
				b=b.mod(BigInteger.valueOf(4));
				if(b.compareTo(BigInteger.valueOf(1))==0)
					System.out.println(7);
				else if(b.compareTo(BigInteger.valueOf(2))==0)
					System.out.println(9);
				else if(b.compareTo(BigInteger.valueOf(3))==0)
					System.out.println(3);
				else if(b.compareTo(BigInteger.valueOf(0))==0)
					System.out.println(1);
			}
			else if(a.compareTo(BigInteger.valueOf(8))==0)
			{
				b=b.mod(BigInteger.valueOf(4));
				if(b.compareTo(BigInteger.valueOf(1))==0)
					System.out.println(8);
				else if(b.compareTo(BigInteger.valueOf(2))==0)
					System.out.println(4);
				else if(b.compareTo(BigInteger.valueOf(3))==0)
					System.out.println(2);
				else if(b.compareTo(BigInteger.valueOf(0))==0)
					System.out.println(6);
			}
			else if(a.compareTo(BigInteger.valueOf(9))==0)
			{
				b=b.mod(BigInteger.valueOf(4));
				if(b.compareTo(BigInteger.valueOf(1))==0)
					System.out.println(9);
				else
					System.out.println(1);
			}
			
		}
	}
}
shaon_cse_cu08
New poster
Posts: 50
Joined: Tue May 25, 2010 9:10 am
Contact:

Re: 10515 - Power et al.

Post by shaon_cse_cu08 »

I think the judge input data sets for this problem is weak... :lol: :lol:
Data set contains n=0 for only the last case...
I gor AC with
if(n[0]=='0')
return 0; 8) :lol:

But there should be case like this :
Input: 2547 0
Output: 1
Sooo funnyyy....

and guys This is sooo number theory.... just try to find the last digit of 'm' & ckeck only da last two digit of 'n'...

suppose.. m=298 n=10363
Here last digit of m=8 so check only the recurrence of last digit of 8 that is 8,4,2,6
And last 2 digits of n=63.. 63%4 = 3
The 3rd recurrence of 8 is 2...
SO the ans is 2... :wink:
I'll keep holding on...Until the walls come tumbling down...And freedom is all around ..... :x
Post Reply

Return to “Volume 105 (10500-10599)”