Page 7 of 9

Posted: Fri Dec 16, 2005 10:12 pm
by sohel_cuet_cse
Hi bayzid i think osan have given a solution 2 ur problem solving technique. About input taking i will sugest u 2 take input as string.
Then by using strlen(),determine the length.then work with last 2 digits. Dont worry it will not cause u TLE or WA.Good Luck :) .

Posted: Sat Dec 17, 2005 7:45 am
by chunyi81
jjtse, try this input:

Code: Select all

0 100
Correct output is

Code: Select all

0
But your code outputs:

Code: Select all

1

Posted: Tue Jul 18, 2006 1:08 pm
by Kallol
Well,
I do not agree that , considering the last two digits of n is enough for this problem and this is why most of the WAs are happenning. I have read most of the posts of the people who are considering the last two digits and gtting WA and complaining here in this forum.

Just check out the following input:

2 100

now if u only consider the last two digits of n , u will get 0
0%4==0
and 2^0 = 1

so, u have the answer 1 , but any power of two can never be an odd number. here the answer should be , 6.

I think checking this will help people a lot

P.S. checking the last digit for m is enough , though.

Posted: Sat Jul 22, 2006 8:41 pm
by vinit_iiita

Code: Select all

#include<iostream>
#include<vector>
using namespace std;
int main()
{
    int m,n;
    while (cin>>m>>n)
    {
       if(!(m==0 && n==0))
       {
          if (n>0)
          {int a;
          while (m>=10)
          m=m%10;
          int t=m;
        
          for (int i=1;i<n;i++)         
          {
              t=t*m;
              
              t=t%10;
            
              }
              cout<<t<<endl;
              }
              else
              cout<<"1"<<endl;
              }  
              else
              exit(0);
              }
              
              
              return 0;
              }     
                
i am getting tle although this is farely faster code...
plz help me... :-?

Posted: Sun Jul 23, 2006 3:37 pm
by Kallol
No reason NOT to get TLE ...LOL

why r using a loop for N . Nac can be very large . U jut need to know the last few digits of N.Have u seen the limit of m and n? How did u use integer for taking the inputs for m and n?? Use string for taking input of M and N . Another thin is , why are u writing

while(M>=10)
m%=10;

will this loop execute more than once for any value of m ??

whatever that certainly didnt cause u TLE. Take input as string and consider the last signifant digits of n. That will do the trick. Thanx.

Wrong Answer

Posted: Sat Aug 19, 2006 8:41 pm
by milacao
Hi all,
I'm getting WA, although my code solves correctly the problem for the input cases you describe. Here it is:

Code: Select all

Code removed after AC
Could someone give me some test case where it is wrong, or why?
Thanks!

Re: Wrong Answer

Posted: Wed Aug 23, 2006 10:49 pm
by Martin Macko
milacao wrote:Hi all,
I'm getting WA, although my code solves correctly the problem for the input cases you describe. Here it is:
Not working for:

Code: Select all

24068 79330
0 0
Correct answer:

Code: Select all

4

Got Accepted!

Posted: Sun Aug 27, 2006 11:36 pm
by milacao
Thanks Martin,
Now I got AC. The problem was one of the numbers in the row correspondent to cypher 8, where I had a typo.
Regards.

Posted: Thu May 31, 2007 4:06 am
by algoJo
I got Runtime Error :o , can someone show me why?

Code: Select all

AC-ed
thanks for replying Jan :lol:

Posted: Thu May 31, 2007 12:58 pm
by Jan
I don't know why you are getting RTE. But your is not fully correct. For cases like 100 0, output should be 1.

10515 - TLE How could this be??! ;-(

Posted: Wed Dec 05, 2007 5:02 pm
by tmnq

Code: Select all

import java.util.*;
public class Main
{
	static boolean isZero(String s)
	{
		for (int i=s.length()-1; i>=0; i--)
		{
			if (s.charAt(i)!=48) return false;
		}
		//if (Integer.parseInt(s)!=0)	return false;
		//if (s.length()==1 && s.charAt(0)==48) return true;
		return false;
	}
	public static void main(String args[])
	{
		int [][] a= {
				{1},{},{6,2,4,8},{1,3,9,7},{6,4},{},{},{1,7,9,3},{6,8,4,2},{1,9}
		};
		int mod4[]= new int[100];
		int mod2[]= new int[10];
		for (int i=0; i<10; i++) mod2[i]= i%2;
		for (int i=0; i<100; i++) mod4[i]= i%4;
		Scanner scn= new Scanner(System.in);
		while (true)
		{
			String s1= scn.next();
			String s2= scn.next();
			//System.out.printf("%s", s1.substring(s1.length()-1));
			int c= s1.charAt(s1.length()-1)-48;
			int end_1= s2.charAt(s2.length()-1)-48;			
			if (c==0 && end_1==0)
			{
				if (isZero(s1) && isZero(s2)) break;
			}			
			switch (c)
			{
				case 0: case 1: case 5: case 6:
					System.out.printf("%d\n", c);
					break;
				case 2: case 3: case 7: case 8:
					int end_2;
					if (s2.length()>=2) end_2= (s2.charAt(s2.length()-2)-48)*10+end_1;
					else end_2= end_1;
					System.out.printf("%d\n", a[c][mod4[end_2]]);
					break;
				case 4: case 9:
					System.out.printf("%d\n", a[c][mod2[end_1]]);
					break;
			}
		}
	}
}
Hi all, above is my code for 10515 - Power et al. I don't get WA but always TLE. I don't understand why i get this error. It seems because of the isZero(String s) function scannig the string.

But even i check if (s.equals("0")) the judge still returns TLE.

Could anyone please help me? ;-( Thanks in advance!

Posted: Thu Dec 20, 2007 12:53 pm
by lennie_2nd
sorry, can the input contain more than one space / leading / trailing zero?

i keep gaining WA and i dont know why..i've checked with the inputs given in the page and my code returned it right. do any of you have a critical testcase for me to try?

thanks in advance

Re: 10515 - Power et al.

Posted: Fri Jun 13, 2008 1:44 pm
by sreejond
Streange I Got TLE???????
I can't understand why I got TLE?
Can any one help me?

Here is my code:

Code: Select all

#include<stdio.h>
#include<string.h>
#include<math.h>
#define MAX 10000

char m[1111],n[1111],fir[10],sec[10],res[1111];

/***********************************************************************************************/
void reverse(char *from,char *to)
{
	long len,l;
	len=strlen(from);
	for(l=0;l<len;l++)
		to[l]=from[len-l-1];
	to[len]='\0';
}
/***********************************************************************************************/
void call_mult(char *first,char *sec,char *result)
{
	char F[MAX],S[MAX],temp[MAX];
	long f_len,s_len,f,s,r,t_len,hold,res;
	f_len=strlen(first);
	s_len=strlen(sec);
	reverse(first,F);
	reverse(sec,S);
	t_len=f_len+s_len;
	r=-1;
	for(f=0;f<=t_len;f++)
		temp[f]='0';
	temp[f]='\0';
	for(s=0;s<s_len;s++)
	{
		hold=0;
		for(f=0;f<f_len;f++)
		{
			res=(F[f]-'0')*(S[s]-'0')+hold+(temp[f+s]-'0');
			temp[f+s]=res%10+'0';
			hold=res/10;
			if(f+s>r)
				r=f+s;
		}
		while(hold!=0)
		{
			res=hold+(temp[f+s]-'0');
			temp[f+s]=res%10+'0';
			hold=res/10;
			if(f+s>r)
				r=f+s;
			f++;
		}
	}
	for(r=r+1;r>0 && (temp[r]=='0' && temp[r-1]!='0');r--)
		temp[r]='\0';
	reverse(temp,result);
}
/***********************************************************************************************/

int main()
{
	long i,r,num1,num2,len1,len2,pos1,pos2,len,k,j;
	while(scanf("%s %s",m,n)==2)
	{
		len1=strlen(m);
		len2=strlen(n);
		if(len1==1 && m[0]=='0' && len2==1 && n[0]=='0')
			break;
		if(n[0]=='0')
		{
			printf("1\n");
			continue;
		}
		if(n[0]=='1' && len2==1)
		{
			printf("%c\n",m[len1-1]);
			continue;
		}
		if(len1>1)
			pos1=len1-1;
		else
			pos1=0;
		if(len2>2)
			pos2=len2-2;
		else
			pos2=0;

		k=0;
		for(i=pos1;i<len1;i++)
			fir[k++]=m[i];
		fir[k]=0;
		k=0;
		for(i=pos2;i<len2;i++)
			sec[k++]=n[i];
		sec[k]=0;

		num2=0;
		for(i=0;i<k;i++)
			num2=(num2*10)+(sec[i]-48);

		sec[0]=fir[0];
		sec[1]=0;
	
		for(i=0;i<num2-1;i++)
		{
			k=0;
			call_mult(fir,sec,res);
			len=strlen(res);
			for(j=0;j<len;j++)
				sec[k++]=res[j];
			sec[k]=0;
		}
		
		len=strlen(res);
		r=res[len-1]-48;
		printf("%ld\n",r);
	}
	return 0;
}

Re: 10515 - Power et al.

Posted: Thu Nov 20, 2008 4:58 pm
by Md. Mijanur Rahman
/*
What's the problem of my code please anyone inform me.
I got wrong answer :oops: .
*/

#include<stdio.h>

int main()
{

long long b,m,p,a[10000],i,x,power,j;

while(scanf("%lld %lld",&b,&p)==2)
{
if((b==0)&&(p==0))
break;
m=10;
i=0;
while(p!=0)
{
a[i++]=p%2;
p=p/2;
}
x=1;
power=b%m;
for(j=0;j<i;j++)
{
if(a[j]==1)
x=(x*power)%m;
power=(power*power)%m;
}
printf("%lld\n",x);

}
return 0;
}

Re: 10515 - Power et al.

Posted: Thu Dec 25, 2008 12:25 pm
by abid_iut
I think this code is giving correct output for every input is the board
But still WA
what is the problem??
pls someone help
here is the code:

Code: Select all

#include<iostream.h>
#include<stdio.h>
#include<string.h>

int num[12][10];
long m,n,i,j,l1,l2,t;
char str1[1000],str2[1000];

int main()
{
		num[0][1]=0;num[0][2]=0;num[0][3]=0;num[0][4]=0;
		num[1][1]=1;num[1][2]=1;num[1][3]=1;num[1][4]=1;
		num[2][1]=2;num[2][2]=4;num[2][3]=8;num[2][4]=6;
		num[3][1]=3;num[3][2]=9;num[3][3]=7;num[3][4]=1;
		num[4][1]=4;num[4][2]=6;num[4][3]=4;num[4][4]=6;
		num[5][1]=5;num[5][2]=5;num[5][3]=5;num[5][4]=5;
		num[6][1]=6;num[6][2]=6;num[6][3]=6;num[6][4]=6;
		num[7][1]=7;num[7][2]=9;num[7][3]=3;num[7][4]=1;
		num[8][1]=8;num[8][2]=4;num[8][3]=2;num[8][4]=6;
		num[9][1]=9;num[9][2]=1;num[9][3]=9;num[9][4]=1;

	while(cin>>str1>>str2){
		if(str1[0]=='0' && str2[0]=='0')break;
		l1=strlen(str1);
		m=str1[l1-1]-'0';
		l2=strlen(str2);
		if(l2>1){
			t=str2[l2-2]-'0';
			n=t*10;
			t=str2[l2-1]-'0';
			n+=t;
		}
		else n=str2[l2-1]-'0';
		if(n==0)printf("1\n");
		else {
			n=n%4;
			if(n==0)n=4;
			printf("%d\n",num[m][n]);
		}
	}
	return 0;
}