[ create a new paste ] login | about

Link: http://codepad.org/u6cevNJn    [ raw code | output | fork ]

C, pasted on Jun 12:
#include <stdio.h>
#include <stdlib.h>
#define M 1000000007
unsigned long long int N;
unsigned long long int **t;
unsigned long long int ** matrix(unsigned long long int **s)
{
    for(unsigned long long int i = 0; i < 3; i++)
    {
        t[i][0] = s[i][0]%M;
        t[i][1] = s[i][1]%M;
        t[i][2] = s[i][2]%M;
    }
    for(unsigned long long int i = 0; i < 3; i++)
    {
        s[i][0] = (t[i][0]*1)%M + (t[i][1]*1)%M + (t[i][2]*0)%M;
        s[i][1] = (t[i][0]*2)%M + (t[i][1]*0)%M + (t[i][2]*1)%M;
        s[i][2] = (t[i][0]*1)%M + (t[i][1]*0)%M + (t[i][2]*0)%M;
    }
    return s;
}
unsigned long long int ** matrixx(unsigned long long int **s)
{
    for(unsigned long long int i = 0; i < 3; i++)
    {
        t[i][0] = s[i][0]%M;
        t[i][1] = s[i][1]%M;
        t[i][2] = s[i][2]%M;
    }
    for(unsigned long long int i = 0; i < 3; i++)
    {
        s[i][0] = (t[i][0]*t[0][0])%M + (t[i][1]*t[1][0])%M + (t[i][2]*t[2][0])%M;
        s[i][1] = (t[i][0]*t[0][1])%M + (t[i][1]*t[1][1])%M + (t[i][2]*t[2][1])%M;
        s[i][2] = (t[i][0]*t[0][2])%M + (t[i][1]*t[1][2])%M + (t[i][2]*t[2][2])%M;
    }
    return s;
}
unsigned long long int ** power(unsigned long long int n, unsigned long long int **s)
{
    if(n == 1 && n == N - 3) return s;
    else if((n % 2 == 0))
    {
        unsigned long long int **p = power(n / 2, s);
        return matrixx(p);
    }else if(n % 2 == 1 && n != 1)
    {
        unsigned long long int **p = power(n - 1, s);
        return matrix(p);
    }else if(n == 1) return s;
}
int main(void)
{
    unsigned long long int k;
    scanf("%llu", &k);
    while(k--)
    {
        scanf("%llu", &N);
        unsigned long long int **s = (unsigned long long int**)malloc(3*sizeof(unsigned long long int));
        t = (unsigned long long int**)malloc(3*sizeof(unsigned long long int));
        for(unsigned long long int i = 0; i < 3; i++)
        {
            s[i] = (unsigned long long int*)malloc(3*sizeof(unsigned long long int));
            s[i][0] = 0;
            s[i][1] = 0;
            s[i][2] = 0;
        }
        s[0][0] = 1;
        s[0][1] = 2;
        s[0][2] = 1;
        s[1][0] = 1;
        s[2][1] = 1;
        for(unsigned long long int i = 0; i < 3; i++)
        {
            t[i] = (unsigned long long int*)malloc(4*sizeof(unsigned long long int));
            t[i][0] = s[i][0];
            t[i][1] = s[i][1];
            t[i][2] = s[i][2];
        }
        if(N == 1) printf("1\n");
        else if(N == 2) printf("12\n");
        else if(N == 3) printf("13\n");
        else
        {
            s = power(N - 3, s);
            unsigned long long int ans = (13 * (s[0][0]%M)) + (12 * (s[0][1]%M)) + (1 * (s[0][2]%M));
            printf("%llu\n", ans%M);
        }
    }

    return 0;
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
In function 'matrix':
Line 8: error: 'for' loop initial declaration used outside C99 mode
Line 14: error: redefinition of 'i'
Line 8: error: previous definition of 'i' was here
Line 14: error: 'for' loop initial declaration used outside C99 mode
In function 'matrixx':
Line 24: error: 'for' loop initial declaration used outside C99 mode
Line 30: error: redefinition of 'i'
Line 24: error: previous definition of 'i' was here
Line 30: error: 'for' loop initial declaration used outside C99 mode
In function 'main':
Line 60: error: 'for' loop initial declaration used outside C99 mode
Line 72: error: redefinition of 'i'
Line 60: error: previous definition of 'i' was here
Line 72: error: 'for' loop initial declaration used outside C99 mode


Create a new paste based on this one


Comments: