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:
View Code
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
相关文章推荐
- 结队编程
- 自述
- oracle监听和实例的启动顺序
- Android: Fragment中getActivity()返回null的问题
- 枚举
- vim常用配置
- 又一大坑
- Mac OSX:Powerline风格的zsh配置
- 详解java类的生命周期(笔者按自己知识量有少量添加)
- 最近的
- iOS8以后UIAlertView和UIActionSheet两种alert页面都将通过UIAlertController来创建
- lvs的健康检测脚本
- Mysql安装
- gethostbyname() -- 用域名或主机名获取IP地址
- 如何参与Linux内核开发(转)
- PLSQL导入数据及遇到问题
- VB编程小练习
- mysql分页原理和sqlserver里面序列的用法
- ZOJ 2987
- Git:如何还原一个已经同步到远程仓库的Commit?