#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define fillchar(a, x) memset(a, x, sizeof(a))
typedef long long ll;
typedef pair< int , int > pii;
typedef unsigned long long ull;
#ifndef ONLINE_JUDGE
void RI(vector< int >&a, int n){a.resize(n); for ( int i=0;i<n;i++) scanf ( "%d" ,&a[i]);}
void RI(){} void RI( int &X){ scanf ( "%d" ,&X);} template < typename ...R>
void RI( int &f,R&...r){RI(f);RI(r...);} void RI( int *p, int *q){ int d=p<q?1:-1;
while (p!=q){ scanf ( "%d" ,p);p+=d;}} void print(){cout<<endl;} template < typename T>
void print( const T t){cout<<t<<endl;} template < typename F, typename ...R>
void print( const F f, const R...r){cout<<f<< ", " ;print(r...);} template < typename T>
void print(T*p, T*q){ int d=p<q?1:-1; while (p!=q){cout<<*p<< ", " ;p+=d;}cout<<endl;}
#endif
template < typename T> bool umax(T&a, const T&b){ return b<=a? false :(a=b, true );}
template < typename T> bool umin(T&a, const T&b){ return b>=a? false :(a=b, true );}
template < typename T>
void V2A(T a[], const vector<T>&b){ for ( int i=0;i<b.size();i++)a[i]=b[i];}
template < typename T>
void A2V(vector<T>&a, const T b[]){ for ( int i=0;i<a.size();i++)a[i]=b[i];}
const double PI = acos (-1.0);
const int INF = 1e9 + 7;
/* -------------------------------------------------------------------------------- */
struct BigInt {
const static int maxI = 1e8;
const static int Len = 8;
typedef vector< int > vi;
typedef long long LL;
vi num;
bool symbol;
BigInt() {
num.clear();
symbol = 0;
}
BigInt( int x) {
symbol = 0;
if (x < 0) {
symbol = 1;
x = -x;
}
num.push_back(x % maxI);
if (x >= maxI) num.push_back(x / maxI);
}
BigInt( bool s, vi x) {
symbol = s;
num = x;
}
BigInt( char s[]) {
int len = strlen (s), x = 1, sum = 0, p = s[0] == ‘-‘ ;
symbol = p;
for ( int i = len - 1; i >= p; i--) {
sum += (s[i] - ‘0‘ ) * x;
x *= 10;
if (x == 1e8 || i == p) {
num.push_back(sum);
sum = 0;
x = 1;
}
}
while (num.back() == 0 && num.size() > 1) num.pop_back();
}
void push( int x) {
num.push_back(x);
}
BigInt abs () const {
return BigInt( false , num);
}
bool smaller( const vi &a, const vi &b) const {
if (a.size() != b.size()) return a.size() < b.size();
for ( int i = a.size() - 1; i >= 0; i--) {
if (a[i] != b[i]) return a[i] < b[i];
}
return 0;
}
bool operator < ( const BigInt &p) const {
if (symbol && !p.symbol) return true ;
if (!symbol && p.symbol) return false ;
if (symbol && p.symbol) return smaller(p.num, num);
return smaller(num, p.num);
}
bool operator > ( const BigInt &p) const {
return p < * this ;
}
bool operator == ( const BigInt &p) const {
return !(p < * this ) && !(* this < p);
}
bool operator >= ( const BigInt &p) const {
return !(* this < p);
}
bool operator <= ( const BigInt &p) const {
return !(p < * this );
}
vi add( const vi &a, const vi &b) const {
vi c;
c.clear();
int x = 0;
for ( int i = 0; i < a.size(); i++) {
x += a[i];
if (i < b.size()) x += b[i];
c.push_back(x % maxI);
x /= maxI;
}
for ( int i = a.size(); i < b.size(); i++) {
x += b[i];
c.push_back(x % maxI);
x /= maxI;
}
if (x) c.push_back(x);
while (c.back() == 0 && c.size() > 1) c.pop_back();
return c;
}
vi sub( const vi &a, const vi &b) const {
vi c;
c.clear();
int x = 1;
for ( int i = 0; i < b.size(); i++) {
x += maxI + a[i] - b[i] - 1;
c.push_back(x % maxI);
x /= maxI;
}
for ( int i = b.size(); i < a.size(); i++) {
x += maxI + a[i] - 1;
c.push_back(x % maxI);
x /= maxI;
}
while (c.back() == 0 && c.size() > 1) c.pop_back();
return c;
}
vi mul( const vi &a, const vi &b) const {
vi c;
c.resize(a.size() + b.size());
for ( int i = 0; i < a.size(); i++) {
for ( int j = 0; j < b.size(); j++) {
LL tmp = (LL)a[i] * b[j] + c[i + j];
c[i + j + 1] += tmp / maxI;
c[i + j] = tmp % maxI;
}
}
while (c.back() == 0 && c.size() > 1) c.pop_back();
return c;
}
vi div ( const vi &a, const vi &b) const {
vi c(a.size()), x(1, 0), y(1, 0), z(1, 0), t(1, 0);
y.push_back(1);
for ( int i = a.size() - 1; i >= 0; i--) {
z[0] = a[i];
x = add(mul(x, y), z);
if (smaller(x, b)) continue ;
int l = 1, r = maxI - 1;
while (l < r) {
int m = (l + r + 1) >> 1;
t[0] = m;
if (smaller(x, mul(b, t))) r = m - 1;
else l = m;
}
c[i] = l;
t[0] = l;
x = sub(x, mul(b, t));
}
while (c.back() == 0 && c.size() > 1) c.pop_back();
return c;
}
BigInt operator + ( const BigInt &p) const {
if (!symbol && !p.symbol) return BigInt( false , add(num, p.num));
if (!symbol && p.symbol) {
return * this >= p. abs () ?
BigInt( false , sub(num, p.num)) : BigInt( true , sub(p.num, num));
}
if (symbol && !p.symbol) {
return (* this ). abs () > p ?
BigInt( true , sub(num, p.num)) : BigInt( false , sub(p.num, num));
}
return BigInt( true , add(num, p.num));
}
BigInt operator - ( const BigInt &p) const {
return * this + BigInt(!p.symbol, p.num);
}
BigInt operator * ( const BigInt &p) const {
BigInt res(symbol ^ p.symbol, mul(num, p.num));
if (res.symbol && res.num.size() == 1 && res.num[0] == 0)
res.symbol = false ;
return res;
}
BigInt operator / ( const BigInt &p) const {
if (p == BigInt(0)) return p;
BigInt res(symbol ^ p.symbol, div (num, p.num));
if (res.symbol && res.num.size() == 1 && res.num[0] == 0)
res.symbol = false ;
return res;
}
BigInt operator % ( const BigInt &p) const {
return * this - * this / p * p;
}
void show() const {
if (symbol) putchar ( ‘-‘ );
printf ( "%d" , num[num.size() - 1]);
for ( int i = num.size() - 2; i >= 0; i--) {
printf ( "%08d" , num[i]);
}
putchar ( ‘\n‘ );
}
int TotalDigit() const {
int x = num[num.size() - 1] / 10, t = 1;
while (x) {
x /= 10;
t++;
}
return t + (num.size() - 1) * Len;
}
};
const int md = 258280327;
BigInt f[1234];
char s[1000];
void pre_init() {
f[0] = 0;
f[1] = f[2] = 1;
for ( int i = 3; i <= 1111; i ++) {
f[i] = f[i - 1] + f[i - 2];
}
}
int main() {
#ifndef ONLINE_JUDGE
freopen ( "in.txt" , "r" , stdin);
//freopen("out.txt", "w", stdout);
#endif // ONLINE_JUDGE
pre_init();
int T;
cin >> T;
while (T --) {
int n;
cin >> n;
scanf ( "%s" , s);
BigInt buf(s);
int L = 1, R = 1111;
while (L < R) {
int M = (L + R) >> 1;
if (f[M] > buf + 1) R = M;
else L = M + 1;
}
((buf - f[L - 2]) % md).show();
}
return 0;
}
|