ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1586. Threeprime Numbers

WA8
Posted by Cat36 2 Nov 2008 06:04
#include <iostream>
using namespace std;

int pr[143]={
101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173,
179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257,
263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349,
353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439,
443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541,
547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631,
641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733,
739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829,
839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941,
947, 953, 967, 971, 977, 983, 991, 997};

unsigned int mod = 1000000009;

struct matrix{
unsigned int a[143][143];
};

matrix operator *(matrix& a, matrix &b){
    matrix c;
    for(int i=0; i<143; ++i) for(int j=0; j<143; ++j){
     __int64 r =0;
     __int64 r1=0;
     for(int k=0; k<143; ++k){
         r1 = a.a[i][k];
         r+=r1*b.a[k][j];
     };
       c.a[i][j] = r%mod;
    };
  return c;
};

matrix pow(matrix a, int n){
matrix res;
for(int i=0; i<143; ++i)for(int j=0; j<143; ++j) res.a[i][j] = (i==j)?1:0;
matrix mul =a;
while(n){
 if(n%2) res = res*mul;
 n/=2;
 mul=mul*mul;
};
return res;
};

int main(){
int n;
cin>>n;
matrix a;
for(int i=0; i<143; ++i)for(int j=0; j<143; ++j) a.a[i][j] = (pr[i]%100==pr[j]/10)?1:0;
a=pow(a,n-3);
__int64 res =0;
for(int i=0; i<143; ++i)for(int j=0; j<143; ++j)res+= a.a[i][j];
cout<< res%mod;
};
WA8
Posted by Cat36 2 Nov 2008 06:05
Need help
Re: WA8
Posted by Cat36 2 Nov 2008 06:09
Переполнялся __int64
Сорри за русский, я в шоке