Educational Codeforces Round 13 (ABCD ....ing)
来源:互联网 发布:java需要英语基础吗 编辑:程序博客网 时间:2024/05/21 06:18
678A - Johny Likes Numbers
#include <bits/stdc++.h>#define met(a,b) memset(a,b,sizeof(a))#define inf (1<<28)#define mod 1000000007#define MAXN 1000 + 10#define MAXM 100000using namespace std;typedef long long LL;typedef long double LD;const double PI = acos(-1.0);const double eps = 1e-6;int n,m;int main(){ int i,j; cin>>n>>m; i = 1; while(m*i <= n) i++; cout<<m*i<<endl;return 0;}
678B - The Same Calendar
#include <bits/stdc++.h>#define met(a,b) memset(a,b,sizeof(a))#define inf (1<<28)#define mod 1000000007#define MAXN 1000 + 10#define MAXM 100000using namespace std;typedef long long LL;typedef long double LD;const double PI = acos(-1.0);const double eps = 1e-6;int cmp(int y){if(y%400 == 0 || (y%4==0 && y%100 !=0)) return 1;else return 0;}int n;int main(){ int i,j; cin>>n; LL sum = 0 ; for(i=n; ;i++) { sum += 365 + cmp(i); if((1 + sum ) % 7 == 1 && cmp(n) == cmp(i+1)) { cout<<i+1<<endl;break;}}return 0;}
678C - Joty and Chocolate
#include <bits/stdc++.h>#define met(a,b) memset(a,b,sizeof(a))#define inf (1<<28)#define mod 1000000007#define MAXN 1000 + 10#define MAXM 100000using namespace std;typedef long long LL;typedef long double LD;const double PI = acos(-1.0);const double eps = 1e-6;LL gcd(LL a,LL b){return b==0?a:gcd(b,a%b);}LL n,a,b,p,q;int main(){ int i,j; cin>>n>>a>>b>>p>>q; LL lcd = a*(b/gcd(a,b)); i = n / lcd;cout<<max((n/a-i)*p+(n/b)*q,(n/a)*p+(n/b-i)*q)<<endl;return 0;}
678D - Iterated Linear Function
#include <bits/stdc++.h>#define met(a,b) memset(a,b,sizeof(a))#define inf (1<<28)#define MAXN 1000000000 + 10#define MAXM 100000using namespace std;typedef long long LL;typedef long double LD;const double PI = acos(-1.0);const double eps = 1e-6;const LL mod = 1000000000 + 7;LL a,b,n,x;LL ksm(LL aa,LL bb,LL mod){LL x = 1;while(bb){if(bb&1) x = (x*aa)%mod;aa = (aa*aa) % mod;bb = bb>>1;}return x;}int main(){ LL i,j; cin>>a>>b>>n>>x; if(a == 1) { cout<<(x+n%mod*b)%mod<<endl;return 0;} LL ans = ksm(a,n,mod); LL sum = ans*x%mod + (ans-1)*ksm(a-1,mod-2,mod)%mod*b%mod; cout<<sum%mod<<endl;return 0;}
327C - Magic Five
快速幂
定义:
满足a*k≡1 (mod p)的k值就是a关于p的乘法逆元。
为什么要有乘法逆元呢?
当我们要求(a/b) mod p的值,且a很大,无法直接求得a/b的值时,我们就要用到乘法逆元。
我们可以通过求b关于p的乘法逆元k,将a乘上k再模p,即(a*k) mod p。其结果与(a/b) mod p等价。
证:(其实很简单。。。)
根据b*k≡1 (mod p)有b*k=p*x+1。
k=(p*x+1)/b。
把k代入(a*k) mod p,得:
(a*(p*x+1)/b) mod p
=((a*p*x)/b+a/b) mod p
=[((a*p*x)/b) mod p +(a/b)] mod p
=[(p*(a*x)/b) mod p +(a/b)] mod p
//p*[(a*x)/b] mod p=0
所以原式等于:(a/b) mod p
这题的关键还是如何求等比数列之和,之前使用的二分求和...这里用数论的知识直接解决...
对于(a/b)%c这类运算不能等价于(a%c / b%c)...但是可以等价为(a*b')%c...其中b'为b的逆元..
而(a*b')%c这类运算可以拆解为(a%c * b%c)..
那么关键就是求c的逆元了.. 值得留意的是10000007是一个质数...
根据费马小定理对于任意的质数p有任意的正整数a满足a^(p-1)%p==1
如果A是a的逆元..那么A*a % p==1...而又a*a^(p-2)%p==a^(p-1)%p==1 所以a的逆元A=a^(p-2)%p
剩下的就简单了..
#include <bits/stdc++.h>#define met(a,b) memset(a,b,sizeof(a))#define inf (1<<28)#define MAXN 1000000000 + 10#define MAXM 100000using namespace std;typedef long long LL;typedef long double LD;const double PI = acos(-1.0);const double eps = 1e-6;const LL mod = 1000000000 + 7;LL a,b,n,x;LL ksm(LL aa,LL bb,LL mod){LL x = 1;while(bb){if(bb&1) x = (x*aa)%mod;aa = (aa*aa) % mod;bb = bb>>1;}return x;}int main(){ int i,j,k; string ss; cin>>ss>>k; LL len = ss.length(); LL ans = 0,x = 1 ; for(i=0;i<len;i++){if(ss[i] == '0' || ss[i] == '5') ans = (ans + x) % mod;x = (x*2) % mod;}LL a1 = ans;LL res = (ksm(ksm(2,len,mod),k,mod) - 1) % mod;res = (res * ans) % mod * ksm(ksm(2,len,mod)-1,mod-2,mod) % mod;cout<<res%mod<<endl;return 0;}
- Educational Codeforces Round 13 (ABCD ....ing)
- Educational Codeforces Round 27 ABCD
- Educational Codeforces Round 13
- Educational Codeforces Round 13
- Codeforces Round 237 ABCD
- 【codeforces】Round #269 ABCD
- Educational Codeforces Round 31(ABCD):有向图求环长度/数据结构贪心
- 【解题报告】Educational Codeforces Round 13
- Educational Codeforces Round 13 E 状压dp
- Educational Codeforces Round 1
- Educational Codeforces Round 2
- Educational Codeforces Round 2
- Educational Codeforces Round 2
- Educational Codeforces Round 3
- Codeforces Educational Round 3
- Codeforces Educational Round 5
- Codeforces Educational round 5
- Educational Codeforces Round 5
- 数据库三范式
- Android 短信验证码自动填写
- 判断TableView ScrollView 是向上滑动,还是向下滑动
- AndroidM如何给所有预装软件所有请求的权限
- jquery如何获取用户表单提交值
- Educational Codeforces Round 13 (ABCD ....ing)
- C++构造函数与析构函数顺序
- cuda及常用计时方式
- 各种端口的作用
- BroadcastReceiver的使用简介
- Eclipse + PyDev快捷键
- LeetCode 168. Excel Sheet Column Title
- Guava-cache
- mac 命令行配置DNS相关操作