UVALive - 7720 The 2016 ACM-ICPC Asia Jakarta Regional Contest J - Super Sum
2017-10-22 23:44
429 查看
第二题。。 更惨的第四发才a。。 一开始这题居然把三个人都看懵了。 仔细一看发现就是求很多个等比数列的和然后相乘。。注意取模和逆元。。wa的很惨啊。 #include<bits/stdc++.h> #define UP(i,l,h) for(int i=l;i<h;i++) #define DOWN(i,h,l) for(int i=h-1;i>=l;i--) #define W(t) while(t) #define MEM(a,b) memset(a,b,sizeof(a)) #define ll long long #define INF 0x3f3f3f3f #define MAXN 2500010 #define eps 1e-10 #define COUT(x) cout<<x<<endl using namespace std; const ll mod=1000000007; ll quick(ll n,ll m) { ll ans=1; while(m) { if(m&1) ans=ans*n%mod; m>>=1; n=n*n%mod; } return ans; } ll exgcd(ll a,ll b,ll &x,ll &y) { if(b==0){x=1,y=0;return a;} else{ll q=exgcd(b,a%b,y,x);y=y-x*(a/b);return q;} } ll niyuan(ll a,ll n) { ll x,y; ll d=exgcd(a,n,x,y); if(d==1) return (x%n+n)%n; else { return -1; } } int main() { int t,ca=1; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); ll ans=1,a,b,c; for(int i=0;i<n;i++) { scanf("%lld%lld%lld",&a,&b,&c); ll s; if(a==1&&c==b) s=1; else if(a==1&&c!=b) s=c-b+1; else s=(quick(a,c)*a-quick(a,b)+mod)%mod*niyuan(a-1,mod)%mod; ans=ans*s%mod; } printf("Case #%d: %lld\n",ca++,ans); } return 0; }
相关文章推荐
- UVALive - 7714 The 2016 ACM-ICPC Asia Jakarta Regional Contest D - Pay Day 脑洞+组合数学
- UVALive - 7715 The 2016 ACM-ICPC Asia Jakarta Regional Contest E - Guessing Game 繁琐的等差数列求和
- UVALive - 7711 The 2016 ACM-ICPC Asia Jakarta Regional Contest A - Confusing Date Format
- UVALive - 7722 The 2016 ACM-ICPC Asia Jakarta Regional Contest L - Tale of a Happy Man dp+线段树
- UVALive 7061 Dire Wolf (dp)(The 2014 ACM-ICPC Asia Beijing Regional Contest D)
- The 2014 ACM-ICPC Asia Shanghai Regional Contest - I - Defeat the Enemy (贪心+multiset)UVALive - 7146
- HDU 5953 Game of Taking Stones(威佐夫博弈+高精度+二分)——The 2016 ACM-ICPC Asia Dalian Regional Contest
- The 2016 ACM-ICPC Asia Dalian Regional Contest
- The 2016 ACM-ICPC Asia Dalian Regional Contest(汇总)
- The 2016 ACM-ICPC Asia Tehran Regional Contest 部分题解!
- uva 7008 The 2014 ACM-ICPC Asia Mudanjiang Regional Contest 【部分题解】
- HDU 3681 Prison Break 二分+搜索 The 35th ACM-ICPC Asia Regional Contest (Hangzhou)
- 【栈+模拟】The 36th ACM/ICPC Asia Regional Beijing Site Online Contest - B Eliminate Witches!
- JAG Practice Contest for ACM-ICPC Asia Regional 2016B题【BFS】
- The 2014 ACM-ICPC Asia Mudanjiang Regional Contest - K Known Notation
- HDU 4063 Aircraft(计算几何)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)
- HDU 5883 The Best Path (欧拉通路) 2016 ACM/ICPC Asia Regional Qingdao Online
- The 2013 ACM-ICPC Asia Changsha Regional Contest - A
- The 2013 ACM-ICPC Asia Changsha Regional Contest J Josephina and RPG
- JAG Practice Contest for ACM-ICPC Asia Regional 2016 C题【贪心】