1. 程式人生 > >Frog and Portal HihoCoder

Frog and Portal HihoCoder

A small frog wants to get to the other side of a river. The frog is initially located at one bank of the river (position 0) and wants to get to the other bank (position 200). Luckily, there are 199 leaves (from position 1 to position 199) on the river, and the frog can jump between the leaves. When at position p, the frog can jump to position p+1 or position p+2.

How many different ways can the small frog get to the bank at position 200? This is a classical problem. The solution is the 201st number of Fibonacci sequence. The Fibonacci sequence is constructed as follows: F1=F2=1;Fn=Fn-1+Fn-2.

Now you can build some portals on the leaves. For each leaf, you can choose whether to build a portal on it. And you should set a destination for each portal. When the frog gets to a leaf with a portal, it will be teleported to the corresponding destination immediately. If there is a portal at the destination, the frog will be teleported again immediately. If some portal destinations form a cycle, the frog will be permanently trapped inside. Note that You cannot build two portals on the same leaf.

Can you build the portals such that the number of different ways that the small frog gets to position 200 from position 0 is M?

Input

There are no more than 100 test cases.

Each test case consists of an integer M, indicating the number of ways that the small frog gets to position 200 from position 0. (0 ≤ M < 232)

Output

For each test case:

The first line contains a number K, indicating the number of portals.

Then K lines follow. Each line has two numbers ai and bi, indicating that you place a portal at position ai and it teleports the frog to position bi.

You should guarantee that 1 ≤ K, ai, bi ≤ 199, and ai ≠ aj if i ≠ j. If there are multiple solutions, any one of them is acceptable.

Sample Input

0
1
5

Sample Output

2
1 1
2 1
2
1 199
2 2
2
4 199
5 5

題意 :一隻青蛙想從0 到 200 ,1 到 199 都有荷葉  ,你可以放置傳送門   讓 A傳送到B  如果 A到A 那麼形成自環                

  現在給你青蛙到200應該有的方案數 ,求怎麼放置傳送門

解 :二進位制拆分 如果需要該位的二進位制那麼連到 199 如果不需要則自環

位置 1 2 3 4 5 6 7 8 9 10 11 12 13 14
方案數/傳送門 自環/連199 1 1 2 2 自/199 2 2 4 4 自/199 4
#include <stdio.h>
#include <algorithm>
#include<string.h>
using namespace std;
#define ll long long
int main()
{
    ll n;
    while(~scanf("%lld",&n))
    {
        printf("65\n");
        if(n&(1ll<<0)) printf("1 199\n");
        else printf("1 1\n");
        for(ll i=1;i<32;i++)
        {
          printf("%lld %lld\n",5+(i-1)*6,5+(i-1)*6);
          if(n&(1ll<<i)) printf("%lld 199\n",7+(i-1)*6);
          else printf("%lld %lld\n",7+(i-1)*6,7+(i-1)*6);
        }
        printf("197 197\n");
        printf("198 198\n");
    }
}