10515 - Powers Et Al.
Moderator: Board moderators
10515 WA..
hi..
I got WA.. I have tested several times with some sample inputs and outputs on board..
The result is exactly right... but. i got WA... why ??
the code is very simple...
first. it tries to get circluar numbers.. and then calculate mod values..
then, get a output value..
but.. why WA ???? please help me...
I got WA.. I have tested several times with some sample inputs and outputs on board..
The result is exactly right... but. i got WA... why ??
the code is very simple...
first. it tries to get circluar numbers.. and then calculate mod values..
then, get a output value..
but.. why WA ???? please help me...
Code: Select all
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define FALSE 0
#define TRUE 1
void main(void)
{
char table[10];
char str_m[200], str_n[200];
int len_m, len_n;
int m, n, i, cur_value;
while ( 1 )
{
scanf("%s %s", str_m, str_n);
if ( str_m[0] == '0' && str_n[0] == '0' )
break;
memset(table, FALSE, sizeof(table));
len_m = strlen(str_m);
len_n = strlen(str_n);
m = str_m[len_m-1] - 48;
if ( len_n > 1 )
{
n = ( str_n[len_n-2] - 48 ) * 10 + ( str_n[len_n-1] - 48 );
if ( len_n > 2 )
n++;
}
else
n = str_n[0] - 48;
cur_value = 1;
for ( i = 0 ; i < n ; i++ )
{
cur_value *= m;
cur_value %= 10;
if ( table[cur_value] == FALSE )
{
table[cur_value] = TRUE;
}
else
break;
}
if ( i == 0 )
cur_value = 1;
else if ( i == n )
cur_value = cur_value;
else
{
n--;
n %= i;
while ( n > 0 )
{
cur_value *= m;
cur_value %= 10;
n--;
}
}
printf("%d\n", cur_value);
}
}
10515 - WA, why? this is imposible!!!!!!!!!!!!!!
type vec=array[1..3000] of byte;
var a,rez,poz,i,m,r:longint;
code:integer;
b:vec;
x,y,z:string;
function rest(a:vec; x:longint):longint;
var i:integer;
begin
r:=0;
for i:=m downto 1 do
r:=(10*r+a) mod x;
rest:=r;
end;
begin
while not eof do
begin
readln(z);
if (z='0 0') then halt;
for i:=1 to length(z) do
if z=' ' then
poz:=i;
x:=copy(z,1,poz-1);
y:=copy(z,poz+1,length(z)-poz+2);
val(x[poz-1],a,code);
m:=length(y);
for i:=1 to m do
val(y,b,code);
if a=1 then rez:=1;
if a=2 then
begin
if rest(b,4)=1 then rez:=2;
if rest(b,4)=2 then rez:=4;
if rest(b,4)=3 then rez:=8;
if rest(b,4)=0 then rez:=6;
end;
if a=3 then
begin
if rest(b,4)=1 then rez:=3;
if rest(b,4)=2 then rez:=9;
if rest(b,4)=3 then rez:=7;
if rest(b,4)=0 then rez:=1;
end;
if a=4 then
begin
if rest(b,2)=0 then rez:=6;
if rest(b,2)=1 then rez:=4;
end;
if a=5 then rez:=5;
if a=6 then rez:=6;
if a=7 then
begin
if rest(b,4)=1 then rez:=7;
if rest(b,4)=2 then rez:=9;
if rest(b,4)=3 then rez:=3;
if rest(b,4)=0 then rez:=1;
end;
if a=8 then
begin
if rest(b,4)=1 then rez:=8;
if rest(b,4)=2 then rez:=4;
if rest(b,4)=3 then rez:=2;
if rest(b,4)=0 then rez:=6;
end;
if a=9 then
begin
if rest(b,2)=1 then rez:=9;
if rest(b,2)=0 then rez:=1;
end;
if a=0 then rez:=0;
if b[1]=0 then rez:=0;
writeln(rez);
end;
end.
This is my source code, Matematicle it is very corect, it should get AC but it gets WA. Please, help me, I don't know what is wrong with this solution. Help!!!
var a,rez,poz,i,m,r:longint;
code:integer;
b:vec;
x,y,z:string;
function rest(a:vec; x:longint):longint;
var i:integer;
begin
r:=0;
for i:=m downto 1 do
r:=(10*r+a) mod x;
rest:=r;
end;
begin
while not eof do
begin
readln(z);
if (z='0 0') then halt;
for i:=1 to length(z) do
if z=' ' then
poz:=i;
x:=copy(z,1,poz-1);
y:=copy(z,poz+1,length(z)-poz+2);
val(x[poz-1],a,code);
m:=length(y);
for i:=1 to m do
val(y,b,code);
if a=1 then rez:=1;
if a=2 then
begin
if rest(b,4)=1 then rez:=2;
if rest(b,4)=2 then rez:=4;
if rest(b,4)=3 then rez:=8;
if rest(b,4)=0 then rez:=6;
end;
if a=3 then
begin
if rest(b,4)=1 then rez:=3;
if rest(b,4)=2 then rez:=9;
if rest(b,4)=3 then rez:=7;
if rest(b,4)=0 then rez:=1;
end;
if a=4 then
begin
if rest(b,2)=0 then rez:=6;
if rest(b,2)=1 then rez:=4;
end;
if a=5 then rez:=5;
if a=6 then rez:=6;
if a=7 then
begin
if rest(b,4)=1 then rez:=7;
if rest(b,4)=2 then rez:=9;
if rest(b,4)=3 then rez:=3;
if rest(b,4)=0 then rez:=1;
end;
if a=8 then
begin
if rest(b,4)=1 then rez:=8;
if rest(b,4)=2 then rez:=4;
if rest(b,4)=3 then rez:=2;
if rest(b,4)=0 then rez:=6;
end;
if a=9 then
begin
if rest(b,2)=1 then rez:=9;
if rest(b,2)=0 then rez:=1;
end;
if a=0 then rez:=0;
if b[1]=0 then rez:=0;
writeln(rez);
end;
end.
This is my source code, Matematicle it is very corect, it should get AC but it gets WA. Please, help me, I don't know what is wrong with this solution. Help!!!
Re: 10515 - WA, why? this is imposible!!!!!!!!!!!!!!
Code: Select all
Please help, I need an explination, I realy need an explination, please I need help!!!!!!
Re: 10515 - WA, why? this is imposible!!!!!!!!!!!!!!
The Timus board is much more active.
Reply On 10515
I am a C++ Programmer.So I Can't Analysis You'r Code.
But I Can Help You With The System Of Solve It.
You Need Only The Last Two Digit Of m,n & Then make it Power(m,n) And Mod By 10 Output The Result.
Some Special Case Occure When m==0&&n==0,m==1&&n==0,m==0,n==1
You Need To Handle This With Special Case.
If You Not Do That System You Can Follow It.
Otherwise If You Wish I Can Send You Some Data.
Good Luck
Rocky
But I Can Help You With The System Of Solve It.
You Need Only The Last Two Digit Of m,n & Then make it Power(m,n) And Mod By 10 Output The Result.
Some Special Case Occure When m==0&&n==0,m==1&&n==0,m==0,n==1
You Need To Handle This With Special Case.
If You Not Do That System You Can Follow It.
Otherwise If You Wish I Can Send You Some Data.
Good Luck
Rocky
Try this input:
your output:
my output (program accepted)
Code: Select all
0 238479283749827394234
1 2340982309420394802
2 2
2 5
3 3
3 74
4 982374982739487239847298374982374982734987
5 23849823498
6 2342
7 444444
8 3999949230402394
8 24
9 2345996959645456
2 0
209384032409803948209 4032094809238409238409
8932749872394729346628364 234972983749823749872394789234
0 0
Code: Select all
0
1
4
2
7
7
4
5
6
1
8
4
1
0
1
6
Code: Select all
0
1
4
2
7
9
4
5
6
1
4
6
1
1
9
6
10515 --WA
I've tried many times, but I still can't find where there is something wrong......
Please help!!!!
------------------------------------------
#include<iostream.h>
int main(void)
{
char a[101],b[101];
int f,s,y,m,n;
while(cin>>a>>b)
{
s=1;
for(f=0;f<=101;f++)
{
if(a[f]==0)
{
if(a[f-1]==48 && a[f-2]>=48)
m=10;
else
m=((int)a[f-1])-48;
break;
}
}
for(f=0;f<=101;f++)
{
if(b[f+1]==0)
{
if(b[f-1]==0)
n=((int)b[f])-48;
else if(b[f-1]==48)
n=100;
else
n=((int)b[f])-48+(((int)b[f-1])-48)*10;
break;
}
}
if(m==0 && n==0)
return 0;
if(m==0 || m==10)
s=0;
if(n==0)
s=1;
if(m>0 && n>0)
{
switch(m)
{
case 1:
n=1;
break;
case 5:
n=1;
break;
case 6:
n=1;
default :
n=n%4+4;
break;
}
for(y=1;y<=n;y++)
s=s*m%10;
}
cout<<s<<endl;
}
return 0;
}
Please help!!!!
------------------------------------------
#include<iostream.h>
int main(void)
{
char a[101],b[101];
int f,s,y,m,n;
while(cin>>a>>b)
{
s=1;
for(f=0;f<=101;f++)
{
if(a[f]==0)
{
if(a[f-1]==48 && a[f-2]>=48)
m=10;
else
m=((int)a[f-1])-48;
break;
}
}
for(f=0;f<=101;f++)
{
if(b[f+1]==0)
{
if(b[f-1]==0)
n=((int)b[f])-48;
else if(b[f-1]==48)
n=100;
else
n=((int)b[f])-48+(((int)b[f-1])-48)*10;
break;
}
}
if(m==0 && n==0)
return 0;
if(m==0 || m==10)
s=0;
if(n==0)
s=1;
if(m>0 && n>0)
{
switch(m)
{
case 1:
n=1;
break;
case 5:
n=1;
break;
case 6:
n=1;
default :
n=n%4+4;
break;
}
for(y=1;y<=n;y++)
s=s*m%10;
}
cout<<s<<endl;
}
return 0;
}
10515 - WA
I don't know what's wrong with my program. Can somebody help me?
_____________________________________________________________
#include <iostream>
#include <string>
using namespace std;
void main() {
string x,y;
unsigned short i,c,cycle,temp,tmp;
int base[10] = {1,1,4,4,2,1,1,4,4,2};
cin >> x >> y;
while ((x!="0")||(y!="0")) {
c=x[x.length()-1]-'0';
if (y.length()==1)
temp=(y[y.length()-1]-'0');
else
temp=(y[y.length()-1]-'0')+(y[y.length()-2]-'0')*10;
if (temp==0)
cout << 1 << endl;
else {
cycle=(temp-1)%base[c];
tmp=c;
for (i=0;i<cycle;i++)
c*=tmp;
cout << c%10 << endl;
}
cin >> x >> y;
}
}
_____________________________________________________________
_____________________________________________________________
#include <iostream>
#include <string>
using namespace std;
void main() {
string x,y;
unsigned short i,c,cycle,temp,tmp;
int base[10] = {1,1,4,4,2,1,1,4,4,2};
cin >> x >> y;
while ((x!="0")||(y!="0")) {
c=x[x.length()-1]-'0';
if (y.length()==1)
temp=(y[y.length()-1]-'0');
else
temp=(y[y.length()-1]-'0')+(y[y.length()-2]-'0')*10;
if (temp==0)
cout << 1 << endl;
else {
cycle=(temp-1)%base[c];
tmp=c;
for (i=0;i<cycle;i++)
c*=tmp;
cout << c%10 << endl;
}
cin >> x >> y;
}
}
_____________________________________________________________
DONT UNDERSTAND!!!!!!
IF INPUT IS 3 74
THEN OUTPUT is 1 => 3^4=81%10=1
IN YOUR RESULT THAT IS 9
HOW IS IT POSSIBLE!!!!!
THEN OUTPUT is 1 => 3^4=81%10=1
IN YOUR RESULT THAT IS 9
HOW IS IT POSSIBLE!!!!!
There are nothing to say about me....
Sorry For Previous Reply
I am Sorry for previous reply...
But I got the same ans that you have shown?
But still wrong Ans...
//HERE MY CODE
#include <stdio.h>
#include <math.h>
#include <string.h>
char s1[200],s2[200];
int m,n,st[12][6];
int main(){
int t,i,j,l1,l2;
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
for(i=0;i<=9;i++){
if(i==0){
for(j=1;j<=4;j++)
st[j]=0;
}
else if(i==1){
for(j=1;j<=4;j++)
st[j]=1;
}
else if(i==2){
st[1]=2;
st[2]=4;
st[3]=8;
st[4]=6;
}
else if(i==3){
st[1]=3;
st[2]=9;
st[3]=7;
st[4]=1;
}
else if(i==4){
st[i][1]=4;
st[i][2]=6;
st[i][3]=4;
st[i][4]=6;
}
else if(i==5){
st[i][1]=5;
st[i][2]=5;
st[i][3]=5;
st[i][4]=5;
}
else if(i==6){
st[i][1]=6;
st[i][2]=6;
st[i][3]=6;
st[i][4]=6;
}
else if(i==7){
st[i][1]=7;
st[i][2]=9;
st[i][3]=3;
st[i][4]=1;
}
else if(i==8){
st[i][1]=8;
st[i][2]=4;
st[i][3]=2;
st[i][4]=6;
}
else if(i==9){
st[i][1]=9;
st[i][2]=1;
st[i][3]=9;
st[i][4]=1;
}
}
while(scanf("%s%s",s1,s2) == 2){
if(s1[0]=='0' && s2[0]=='0')
break;
l1=strlen(s1);
l2=strlen(s2);
m=s1[l1-1]-'0';
n=0;
if(l2>1){
t=s2[l2-2]-'0';
n=t*10;
t=s2[l2-1]-'0';
}
else
t=s2[l2-1]-'0';
n+=t;
if(n==0)
printf("1\n");
else{
n%=4;
if(n==0)
n=4;
printf("%d\n",st[m][n]);
}
}
return 0;
}
Please Help Me....
But I got the same ans that you have shown?
But still wrong Ans...
//HERE MY CODE
#include <stdio.h>
#include <math.h>
#include <string.h>
char s1[200],s2[200];
int m,n,st[12][6];
int main(){
int t,i,j,l1,l2;
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
for(i=0;i<=9;i++){
if(i==0){
for(j=1;j<=4;j++)
st[j]=0;
}
else if(i==1){
for(j=1;j<=4;j++)
st[j]=1;
}
else if(i==2){
st[1]=2;
st[2]=4;
st[3]=8;
st[4]=6;
}
else if(i==3){
st[1]=3;
st[2]=9;
st[3]=7;
st[4]=1;
}
else if(i==4){
st[i][1]=4;
st[i][2]=6;
st[i][3]=4;
st[i][4]=6;
}
else if(i==5){
st[i][1]=5;
st[i][2]=5;
st[i][3]=5;
st[i][4]=5;
}
else if(i==6){
st[i][1]=6;
st[i][2]=6;
st[i][3]=6;
st[i][4]=6;
}
else if(i==7){
st[i][1]=7;
st[i][2]=9;
st[i][3]=3;
st[i][4]=1;
}
else if(i==8){
st[i][1]=8;
st[i][2]=4;
st[i][3]=2;
st[i][4]=6;
}
else if(i==9){
st[i][1]=9;
st[i][2]=1;
st[i][3]=9;
st[i][4]=1;
}
}
while(scanf("%s%s",s1,s2) == 2){
if(s1[0]=='0' && s2[0]=='0')
break;
l1=strlen(s1);
l2=strlen(s2);
m=s1[l1-1]-'0';
n=0;
if(l2>1){
t=s2[l2-2]-'0';
n=t*10;
t=s2[l2-1]-'0';
}
else
t=s2[l2-1]-'0';
n+=t;
if(n==0)
printf("1\n");
else{
n%=4;
if(n==0)
n=4;
printf("%d\n",st[m][n]);
}
}
return 0;
}
Please Help Me....
There are nothing to say about me....
Re: Reply On 10515
[quote="Rocky"]I am a C++ Programmer.So I Can't Analysis You'r Code.
But I Can Help You With The System Of Solve It.
You Need Only The Last Two Digit Of m,n & Then make it Power(m,n) And Mod By 10 Output The Result.
Rocky, u dont need last two digit of m, you only need last digit of m and the last 2 digit of n, Then power them and finally mod the output by 10. You should make it clear before posting.Your advice can only result wrong answer.
Thanks in advance......
But I Can Help You With The System Of Solve It.
You Need Only The Last Two Digit Of m,n & Then make it Power(m,n) And Mod By 10 Output The Result.
Rocky, u dont need last two digit of m, you only need last digit of m and the last 2 digit of n, Then power them and finally mod the output by 10. You should make it clear before posting.Your advice can only result wrong answer.
Thanks in advance......
We the dreamer of the dreamy dream...
Hey guys,
I'm having a problem with this problem. And I don't think the problem is trivial. I used the basic well known idea of getting last digit in m and last 2 digit in n. I tried all the possible inputs I can find, and works fine.
i submitted my C program as a c++ program. got WA.
I submitted my C program as a c program. got CE (compile error)
There must be a header of some sort that I'm forgetting to put in. Can someone compile my code with the correct version of the compiler and execute it? thanks.
I'm having a problem with this problem. And I don't think the problem is trivial. I used the basic well known idea of getting last digit in m and last 2 digit in n. I tried all the possible inputs I can find, and works fine.
i submitted my C program as a c++ program. got WA.
I submitted my C program as a c program. got CE (compile error)
There must be a header of some sort that I'm forgetting to put in. Can someone compile my code with the correct version of the compiler and execute it? thanks.
Code: Select all
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(){
int num, pow;
char s1[2000], s2[2000];
char temp[5];
int i;
int sum;
int cnt;
int len;
int list[10][5] = {
1, 0, 0, 0, 0,
1, 1, 1, 1, 0,
6, 2, 4, 8, 0,
1, 3, 9, 7, 0,
6, 4, 0, 0, 0,
1, 5, 0, 0, 0,
1, 6, 0, 0, 0,
1, 7, 9, 3, 0,
6, 8, 4, 2, 0,
1, 9, 0, 0, 0
};
scanf("%s%s", &s1, &s2);
while ( strcmp(s1, "0") || strcmp(s2, "0")){
len = strlen(s1);
num = atoi(&s1[len-1]);
len = strlen(s2);
cnt = 0;
strcpy (temp, "\0");
if (len > 2){
for (i=len-2; i<len; i++){
temp[cnt++] = s2[i];
}
temp[cnt] = '\0';
}
else {
strcpy(temp, s2);
}
pow = atoi(temp);
switch(num){
case 0:
if (pow != 0)
sum = 0;
else {
sum = 1;
}
break;
case 1:
sum = 1;
break;
case 2: case 3: case 7: case 8:
if (pow == 0)
sum = 1;
else {
pow = pow % 4;
sum = list[num][pow];
}
break;
case 5: case 6:
if (pow == 0)
sum = 1;
else {
sum = num;
}
break;
case 4: case 9:
if (pow == 0)
sum = 1;
else{
pow = pow % 2;
sum = list[num][pow];
}
break;
default: printf("*(#(WUIOJFLSDKFJ\n");
break;
}
printf ("%i\n", sum);
scanf("%s%s", &s1, &s2);
}//end while
return 0;
}