here is only basic implementation of problems for beginners. If you have any problem with any solution or any basic concept of programming or you want more efficient solution you can mail me.
my suggestion is not to copy and paste codes from here try to understand the logic and think why you were not able to solve it.

Tuesday, 9 September 2014

Cards

#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;
}

5 comments:

  1. I read your blog.I thought it was great.. Hope you have a great day. God bless.

    Rica
    www.imarksweb.org

    ReplyDelete
  2. ans=(((3*((((n%1000007)*(n%1000007)))%1000007)+((n)%1000007))%1000007)/2)%1000007;
    I 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.

    ReplyDelete
  3. I have used ans=(((3*((((n%1000007)*(n%1000007)))%1000007)+((n)%1000007))%1000007)/2)%1000007;

    means (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

    ReplyDelete
    Replies
    1. because you have to take care of modular divison also
      (a/b)%m is not equal to (a%m)/b.
      Use modular inverse of 2 to find the answer

      Delete