2017 ACM-ICPC 亚洲区(西安赛区)网络赛 E.Maximum Flow【规律】

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 10000000071000000007 for each test case.

样例输入
2
样例输出
1

题目大意:


给出一个网络,让你求最大流。网络建图方式为:从i到j,流量为i^j,要求i<j;


思路:


暴力打表观察规律,对于结果其二进制下意义每位的价值是固定的。


Ac代码:

#include<stdio.h>
#include<string.h>
#include<math.h>
using namespace std;
#define ll long long int
ll sum[150];
const ll mod=1000000007;
long long q_mul( long long a, long long b, long long mod ) //快速计算 (a*b) % mod
{
    long long ans = 0;  // 初始化
    while(b)                //根据b的每一位看加不加当前a
    {
        if(b & 1)           //如果当前位为1
        {
            b--;
            ans =(ans+ a)%mod;   //ans+=a
        }
        b /= 2;                         //b向前移位
        a = (a + a) % mod;          //更新a

    }
    return ans;
}

long long poww( long long a, long long b, long long mod ) //快速计算 (a^b) % mod
{
    long long ans = 1; // 初始化
    while(b)//根据b的每一位看乘不乘当前a
    {
        if(b & 1)   //如果当前位为1
        {
            ans = q_mul( ans, a, mod ); //ans*=a
        }
        b /= 2;                                     //b向前移位
        a = q_mul( a, a, mod );         //更新a
    }
    return ans;
}

void init()
{
    sum[1]=2;
    sum[2]=2+5;
    for(ll i=3;i<=62;i++)
    {
        sum[i]=sum[i-1]*2;sum[i]=(sum[i]%mod+mod)%mod;
        sum[i]=sum[i]-(ll)poww(2,(i-2)*2,mod);sum[i]=(sum[i]%mod+mod)%mod;
        sum[i]=sum[i]+(ll)poww(2,(i-1)*2,mod);sum[i]=(sum[i]%mod+mod)%mod;
       // sum[i]=sum[i-1]*2-(ll)poww(2,(i-2)*2,mod)+(ll)poww(2,(i-1)*2,mod);
    }
}
int main()
{
    ll n;
    init();
    while(~scanf("%lld",&n))
    {
        n--;
        ll ans=0;
        ll first=0;
        for(ll i=61;i>=0;i--)
        {
            if(((1ll<<i)&n)>0)
            {
                first++;
                if(first>1)
                {
                    ans+=sum[i+1];
                    ans=((ans)%mod+mod)%mod;
                }
                else
                {
                    ans+=1;
                    for(ll j=1;j<=i;j++)
                    {
                        ans+=sum[j];ans=((ans)%mod+mod)%mod;
                    }
                }
            }
        }
        printf("%lld\n",((ans)%mod+mod)%mod);
    }
}









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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值