#include<stdio.h>
int main(){
long long int test,cards,level,x,i;
scanf("%lld",&test);
for(i=0;i<test;i++){
scanf("%d",&level);
x=(level*(level+1))/2-level;
cards=(3*x+2*level)%1000007;
printf("%lld\n",cards);
}
return 0;
}
int main(){
long long int test,cards,level,x,i;
scanf("%lld",&test);
for(i=0;i<test;i++){
scanf("%d",&level);
x=(level*(level+1))/2-level;
cards=(3*x+2*level)%1000007;
printf("%lld\n",cards);
}
return 0;
}
huyanh
ReplyDeleteans=(((3*((((n%1000007)*(n%1000007)))%1000007)+((n)%1000007))%1000007)/2)%1000007;
ReplyDeleteI have used this.
(3*level*level+level)/2
same thing which u have done (in modified way).
but it is giving wrong answer for big numbers.
Why is it so? I have used unsigned long long int.
I have used ans=(((3*((((n%1000007)*(n%1000007)))%1000007)+((n)%1000007))%1000007)/2)%1000007;
ReplyDeletemeans (3*level*level+level)/2
modified way
it is giving wrong answer for big numbers. why is it so? I have used unsigned long long int
because you have to take care of modular divison also
Delete(a/b)%m is not equal to (a%m)/b.
Use modular inverse of 2 to find the answer