Maximum Flow 规律题 2017 ACM-ICPC 亚洲区(西安赛区)网络赛

Given a directed graph with nn nodes, labeled 0,1, \cdots, n-10,1,,n1.

For each <i, j><i,j> satisfies 0 \le i < j < n0i<j<n, there exists an edge from the i-th node to the j-th node, the capacity of which is ii xor jj.

Find the maximum flow network from the 0-th node to the (n-1)-th node, modulo 10000000071000000007.

Input Format

Multiple test cases (no more than 1000010000).

In each test case, one integer in a line denotes n(2 \le n \le 10^{18})n(2n1018).

Output Format

Output the maximum flow modulo 10000000071000000007for each test case.

样例输入
2
样例输出
1


完完全全找的规律,累死

先打了个表,发现其相邻数之差是有规律的

然后就各种调....


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

ll n;
ll er[1000];
ll er1[66];
ll ant[1000];

int main()
{
    er[0] = 1;
    er1[0] =1  ;
    for(int i=1;i<=129;i++)
    {
        er[i] = 2*er[i-1]%MOD;
    }

    for(int i=1;i<=64;i++)
    {
        er1[i] = er1[i-1]*2;
    }

    ant[0] = 2;
    for(int i=1;i<=64;i++)
    {
        ant[i] = er[i*2]+1;
        ant[i]%=MOD;
    }

    ll tt = ant[0];
    ll pr;
    for(int i=1;i<=64;i++)
    {
        pr= ant[i];
        ant[i] = (ant[i]+MOD-tt)%MOD;
        tt = pr;
//        cout <<ant[i]<<endl;
    }
//    freopen("data.txt","r",stdin);
    while(cin >> n)
    {
        if(n==2)
        {
            cout<<1<<endl;
            continue;
        }
        ll ans = 0;
        ll t;
        for(int i=0;i<=64;i++)
        {
            if(n<er1[i])
                break;
            if(n%er1[i]==0)
            {
                t=  n/er1[i];
            }
            else
            {
                t=  n/er1[i]+1;
            }
            t-=2;
            if(t<=0)
            {
                break;
            }
//            cout <<t<<endl;
            t%=MOD;
            ans += t*ant[i];
            ans%=MOD;
        }
        cout << ans+1<<endl;
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值