1 条题解
-
0
C :
#include<stdio.h> #include<stdlib.h> long long ab(int k,int n) { long long t,p; if(k==0) return 1; t=ab(k/2,n); p=(t*t)%n; if(k%2==0) return p; return (p*(10%n))%n; } int main() { int n,m,x,k; long long s,q; while(scanf("%d%d%d%d",&n,&m,&k,&x)!=EOF) { s=ab(k,n); q=(x%n+(s*(m%n))%n)%n; printf("%lld\n",q); } return 0; }
C++ :
#include<stdio.h> long long ab(int k,int n) { long long t; if(k==0)return 1; if(k==1)return 10%n; t=ab(k/2,n); if(k%2==0)return (t*t)%n; return (((t*t)%n)*(10%n))%n; } int main() { int n,m,k,x; long long a; while(scanf("%d%d%d%d",&n,&m,&k,&x)!=EOF) { a=ab(k,n); printf("%lld\n",(x%n+(a*(m%n))%n)%n); } return 0; }
Pascal :
var n,m,k,x:longint; base,t:int64; begin readln(n,m,k,x); base:=10; t:=1; while k>0 do begin if k and 1=1 then t:=t*base mod n; base:=base*base mod n; k:=k>>1; end; writeln((x+m*t) mod n); end.
- 1
信息
- ID
- 315
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者