您的位置:首页 > 其它

zoj 3903 Ant(推公式,逆元)

2015-10-18 22:22 260 查看
AntTime Limit: 1 Second Memory Limit: 32768 KB
There is an ant named Alice. Alice likes going hiking very much. Today, she wants to climb a cuboid. The length of cuboid's longest edge is n, and the other edges are all positive integers. Alice's starting point is a vertex of this cuboid, and she wants to arrive at the opposite vertex. The opposite vertex means the vertex which has no common planes or edges with the starting point. Just like the picture below:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <cstring>
#include <string>
#include <cctype>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef long long LL;
using namespace std;
const LL MOD = 1E9+7;
LL T;
LL n;
LL ans;
LL qpow(LL a,LL b,LL k)
{
LL res = 1;
while (b > 0)
{
if (b & 1)
res = (res*a)%k;
b = b >> 1 ;
a = (a*a)%k;
}
return res;
}

int main()
{

cin>>T;
while (T--)
{
scanf("%lld",&n);
n = n % MOD;

ans = qpow(12,MOD-2,MOD);
//   cout<<"ans:"<<ans<<endl;
ans = (ans*n)%MOD;
//    cout<<"ans:"<<ans<<endl;
ans = ans*(n+1)%MOD;
//    cout<<"ans:"<<ans<<endl;
ans = ans % MOD;
//     cout<<"ans:"<<ans<<endl;

//       cout<<"ans:"<<ans<<endl;

LL tmp = (n*n)%MOD;
tmp = (tmp *13)%MOD;
tmp = (tmp + 13*n)%MOD;
tmp = (tmp + 4)%MOD;
ans = (ans * tmp)%MOD;
printf("%lld\n",ans);
}

return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: