1 solutions
-
0
计算总的轮数,然后模拟每次去的位置
#include<bits/stdc++.h> using namespace std; typedef long long LL; LL n,m,k,x; int main() { cin>>n>>m>>k>>x; LL total=1; for(int i=1;i<=k;i++) //计算总共的轮数 { total=total*10; total%=n; //去掉周期 } for(int i=1;i<=total;i++) //模拟 { x=(x+m)%n; } cout<<x; return 0; }
100pts
需要使用快速幂去优化,为,大于会执行30次左右
#include<bits/stdc++.h> using namespace std; typedef long long LL; LL n,m,k,x; LL qmi(LL a,LL b) { LL ans=1; while(b) { if(b&1) { ans=ans*a%n; } a=a*a%n; b=b>>1; } return ans; } int main() { // LL n,m,k,x; cin>>n>>m>>k>>x; cout<<(x+qmi(10,k)*m)%n; return 0; }
- 1
Information
- ID
- 1100
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 5
- Tags
- # Submissions
- 1
- Accepted
- 1
- Uploaded By