Abd_Codeforce's blog

By Abd_Codeforce, history, 10 months ago, In English

Hello everyone , I am very happy to share that I have finally reached Pupil. I took me around 2 months of dedicated problem solving and learning some new topics(such as number theory , binary search, etc) and some brainstorming sessions to reach here. I am very excited to face the new challenges in my further journey and would like to be in touch with the community . I would love to thank my roommate (Vikalp) for always being with me and supporting me through tough times.

PS :

  1. I love problem solving

  2. My roommate does not know I mentioned him.

Full text and comments »

  • Vote: I like it
  • -4
  • Vote: I do not like it

By Abd_Codeforce, history, 11 months ago, In English

Hello Everyone. Finally I reached 1000 on Codeforces so I decided to post my first Blog. But rather than just talking I wanted to post something helpful for the community in my first blog hence I came up with something for you all(Specifically Newbie's because I am also one).For all the people rated more than me I would appreciate your support (pls don't say newbie opinions don't matter)

So a lot of the newbie don't know how to calculate the nth term of fibonacci series modulo 10^9 + 7 when n is very large like N<=10^18 because it require computation in logN time and also some basic modular Arithmetic so here I am sharing the code to calculate that U can use it as a snippet and make a file of it so that u can import it anytime.

Here it is

define mod 1e9+7

define ll long long

ll modAdd(ll a,ll b){ ll p = (a%mod + b%mod)%mod; return p; }

ll modSub(ll a,ll b){ ll p = (a%mod — b%mod)%mod; if(p<0) p+=mod; return p; }

ll modMul(ll a,ll b){ ll p = (a%mod * b%mod)%mod; return p; }

pair<ll, ll> fib (ll n) { if (n == 0) return {0, 1};

auto p = fib(n >> 1);
ll c = modMul(p.first,modSub(modMul(2,p.second),p.first));
ll d = modAdd(modMul(p.first,p.first),modMul(p.second,p.second));
if (n & 1)
    return {d, modAdd(c,d)};
else
    return {c, d};

}

just call the fib function with N as parameter and it will return a pair of integers {Fn,Fn+1} and u can say fib(N).first to get the value.

If u want the explanation of the code pls comment below. And if you want to make my day special pls upvote this blog.

Full text and comments »

  • Vote: I like it
  • -26
  • Vote: I do not like it