https://www.codechef.com/problems/SUM1
Explanation:
As n can take a value upto 10^16 in the question and n^2 cannot fit in even long long int, we cannot do n*n and then apply %1000000007
So we cannot do (n*n)%1000000007 so we do like this
((n%1000000007)*(n%1000000007))%1000000007
According to modular arithmetic (a*b)%m = ((a%m)*(b%m))%m
Here is the solution:
#include<stdio.h>
#define MOD 1000000007
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
long long int n;
scanf("%lld",&n);
printf("%lld\n",(((n%MOD)*(n%MOD))%MOD));
}
return 0;
}
No comments:
Post a Comment