您的位置:首页 > 理论基础 > 计算机网络

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

2017-09-18 15:36 381 查看
Given a directed graph with nn nodes,
labeled 0,1,
\cdots, n-10,1,⋯,n−1.
For each <i,
j><i,j> satisfies 0
\le i < j < n0≤i<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(2≤n≤10​18​​).

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);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐