Hello Choto Bondhu!

Let’s play a game. I will give you a number n. You will have to tell me n2. Okay, it may seem diffic…

Click here to read the complete problem statement.


If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.

#include<stdio.h>
int main()
{
int i,t;
scanf(“%d”,&t);
int n[t];
for(i=0;i<t;i++){
scanf(“%d”,&n[i]);
}
for(i=0;i<t;i++)
{
printf(“%d\n”,((n[i]*n[i])%10));
}

return 0;

}
//where is the problem?It passed test case 1 but failed in test case 2!

#include 

int main() {
	int t,i,n;
	scanf("%d",&t);
	for(i=0;i<t;i++){
		scanf("%d",&n);
		if(n%10==0){
			printf("%d\n",0);
		}
		else if(n%10==1 || n%10==9){
			printf("%d\n",1);
		}
		else if(n%10==2 || n%10==8){
			printf("%d\n",4);
		}
		else if(n%10==3 || n%10==7){
			printf("%d\n",9);
		}
		else if(n%10==4 || n%10==6){
			printf("%d\n",6);
		}
		else if(n%10==5){
			printf("%d\n",5);
		}
		else if(n%10==0){
			printf("%d\n",0);
		}
	}
	return 0;
}

What’s the bug here?
Why is it failing in test case 4?
Can anyone tell?

I’m no expert at this but I’ve to say it, bro, why did you used printf(“%d\n”,2); you could use printf(“2”); instead in the “cheat”(I thought the same way.).i also think you need long int or long long int in the function cause the squared number are very large than int .in that case every answer would be taken from 1st 8 digits(or maybe 9, I am not sure). so, try that & I’m very sorry for the delay Ana.

sorry but I checked more and found that my previous ans was partially wrong. cause in subtask 3 , " n" has highest value 10^100000 that means 1 lakh digits. I think string may work.

T=int(input())
for i in range(T):
n=int(input())
s=str(n**2)
print(int(s[len(s)-1:]))

I am exceeding CPU limit in the last case. Any suggestions on what i can do?