## 10515 - Powers Et Al.

Moderator: Board moderators

Master
Learning poster
Posts: 82
Joined: Thu Oct 10, 2002 1:15 pm
Contact:
To calculate m^n you don't need to calculate m^n but just calculate (last digit of m)^n . And the last digit can only be from 0 to 9. For each digit there is a repeated sequence. your task is to find that and then just use a switch statement.

M H Rasel
CUET Old Sailor

yan4546
New poster
Posts: 7
Joined: Fri Nov 15, 2002 4:17 am
Contact:

### I got AC .

2 digits is not enough and 3 digits can do .
aaaaaaaaaaaaaaaaaaaaa

yan4546
New poster
Posts: 7
Joined: Fri Nov 15, 2002 4:17 am
Contact:

### test cases!

Input:
12 10000
1 1000
2313242341234 100000
32872342144876231874687236872364987164876239874698721649823149823749854354356490487239759843 4359000000000000004354354356463464356346435643574839579473950739480702750847d239586345
33333333333333333333333333333333333333333333333333333333333333333333 3222222222234433222222222222222222222342342344444444444
1 1
0 0

output:
6
1
6
3
1
1
aaaaaaaaaaaaaaaaaaaaa

Iwashere
New poster
Posts: 20
Joined: Mon Aug 11, 2003 1:50 pm
Location: Singapore
Anyone can help me with this one? Thanks.

[c]
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

char m[103], n[103], ml[2], nl[2], i;
int mlast, nlast, mlen, nlen;

int main(){
for (;;){
for (i=0; i<103; i++){
m='\0';
n='\0';
}
scanf("%s %s",m,n);
if ((m[0]=='0')&&(m[1]=='\0')&&(n[0]=='0')&&(n[1]=='\0')){
break;
}
mlen=strlen(m)-1;
nlen=strlen(n)-1;
ml[0]=m[mlen];
nl[0]=n[nlen];
mlast=atoi(ml);
nlast=atoi(nl);
if ((n[0]='0')&&(n[1]='\0')){
printf ("0\n");
}
else if (mlast==1){
printf ("1\n");
}
else if (mlast==2){
if (nlast%4==0){
printf("6\n");
}
else if (nlast%4==1){
printf("2\n");
}
else if (nlast%4==2){
printf("4\n");
}
else if (nlast%4==3){
printf("8\n");
}
}
else if (mlast==3){
if (nlast%4==0){
printf("1\n");
}
else if (nlast%4==1){
printf("3\n");
}
else if (nlast%4==2){
printf("9\n");
}
else if (nlast%4==3){
printf("7\n");
}
}
else if (mlast==4){
if (nlast%2==0){
printf("6\n");
}
else if (nlast%2==1){
printf("4\n");
}
}
else if (mlast==5){
printf("5\n");
}
else if (mlast==6){
printf("6\n");
}
else if (mlast==7){
if (nlast%4==0){
printf("1\n");
}
else if (nlast%4==1){
printf("7\n");
}
else if (nlast%4==2){
printf("9\n");
}
else if (nlast%4==3){
printf("3\n");
}
}
else if (mlast==8){
if (nlast%4==0){
printf("6\n");
}
else if (nlast%4==1){
printf("8\n");
}
else if (nlast%4==2){
printf("4\n");
}
else if (nlast%4==3){
printf("2\n");
}
}
else if (mlast==9){
if (nlast%2==0){
printf("1\n");
}
else if (nlast%2==1){
printf("9\n");
}
}
else if (mlast==0){
printf("0\n");
}
}
return 0;
}
[/c]

Towhid
New poster
Posts: 38
Joined: Wed May 28, 2003 5:30 pm
Contact:
Try for the data
15 0
The output should be 1
From 0 to 0

Towhid
New poster
Posts: 38
Joined: Wed May 28, 2003 5:30 pm
Contact:
Oh! I forgot another input for Iwashere.
It is:
2 12
the output is 6.
and so on.............
From 0 to 0

zubair
New poster
Posts: 17
Joined: Fri Apr 18, 2003 2:22 pm
i don't know what's the probs here? i have tested many times but invain
can any body halp me on my code with some test data
[cpp]
arios
[/cpp]
Last edited by zubair on Mon Oct 27, 2003 2:10 pm, edited 1 time in total.
zubair-CUET old sailor

Iwashere
New poster
Posts: 20
Joined: Mon Aug 11, 2003 1:50 pm
Location: Singapore
Found what's wrong.
Some caculation problem and I did not know that n^0=1.
Thank you very much, Towhid

zubair
New poster
Posts: 17
Joined: Fri Apr 18, 2003 2:22 pm
got accepted. thnx
zubair-CUET old sailor

yeameen
New poster
Posts: 1
Joined: Mon Nov 03, 2003 7:28 pm
Contact:
I got TLE? whats wrong with the following code?
[c]
#include <stdio.h>

int main(void)
{
int result, m, n;

while(scanf("%d%d", &m, &n) != EOF) {
if(m == 0)
break;

result = 1;
while(n--)
result = (result * m) % 10;

printf("%d\n", result);
}

return 0;
}
[/c]

bayzid
New poster
Posts: 7
Joined: Sun Sep 14, 2003 8:09 am
Contact:

### 10515 why wrong ans plz help me

#include<stdio.h>

void main()
{
long int m,n; char c;
int l,p,a2[4]={6,2,4,8},a3[4]={1,3,9,7},a4[2]={6,4},a7[4]={1,7,9,3},a8[4]={6,8,4,2},a9[2]={1,9};
int mod2,mod4;
while(2)
{
while((c=getchar())!=' '&&c!='\n'&&c!='\t') m=c-48;

while((c=getchar())!=' '&&c!='\n'&&c!='\t') n=c-48;

if(m==0&&n==0)
break;

mod2=n%2;
mod4=n%4;
p=m%10;
if(n==0)
l=1;
else if(p==0||p==1||p==5||p==6)
l=p;
else if(p==2)
l=a2[mod4];
else if(p==3)
l=a3[mod4];
else if(p==4)
l=a4[mod2];
else if(p==7)
l=a7[mod4];
else if(p==8)
l=a8[mod4];
else if(p==9)
l=a9[mod2];
printf("%d\n",l);
}
}
arahman

Towhid
New poster
Posts: 38
Joined: Wed May 28, 2003 5:30 pm
Contact:
Your idea is wrong. 10^101 is a quite big number having 100 digits. It can't be fitted in integer.
From 0 to 0

Towhid
New poster
Posts: 38
Joined: Wed May 28, 2003 5:30 pm
Contact:
Try the inputs
2 12
3 10
and match them with original output.
Find the outputs yourself
From 0 to 0

osan
New poster
Posts: 47
Joined: Tue Jul 29, 2003 12:03 pm
Contact:
Dear bayzid

Input

Code: Select all

``````17 11
2 12
3 10``````

Code: Select all

``````7
4
1``````
Output should be

Code: Select all

``````3
6
9``````
I think you should hold at least last 2 digit of n.

Code: Select all

``````m=7 & n=1;
1%4= 1;
For the m=7 & n=1
Result = 7.``````
My code

Code: Select all

``````m=7 & n=11
11%4=3;
For m=7 & n=3
Result = 3.``````
i think you got that whatever i wanna say

Good Luck!!!!
this time WA
what next...............?

bayzid
New poster
Posts: 7
Joined: Sun Sep 14, 2003 8:09 am