46 条题解
-
0梦幻空城 LV 10 @ 2015-10-24 11:13:34
/*
Author : Slience_K
Belong : C++
Pro : NOIP 2013 - 1 - 1*/
#include <cstdio>
#define LL long long
using namespace std;
LL n , m , k , x , p;
LL power( LL x ){
if ( x == 0 ) return 1;
LL tem = power( x / 2 );
tem = ( tem * tem ) % n;
if ( x % 2 ) tem = ( tem * 10 ) % n;
return tem;
}
int main(){
freopen( "circle.in" , "r" , stdin );
freopen( "circle.out" , "w" , stdout );
scanf( "%I64d%I64d%I64d%I64d" , &n , &m , &k , &x );
x %= n;
m %= n;
p = power( k );
p = ( x + m * p ) % n;
printf( "%I64d" , p );
fclose( stdin );
fclose( stdout );
return 0;
} -
02015-10-23 19:55:56@
var n,m,x,k,c:longint;
function kuai(a,b,p:int64):int64;
var t,y:int64;
begin
t:=1;
y:=a;
while b<>0 do
begin
if (b and 1)=1 then t:=((t mod p)*(y mod p)) mod p;
y:=((y mod p)*(y mod p)) mod p;
b:=b shr 1;
end;
exit(t);
end;
begin
readln(n,m,k,x);
c:=kuai(10,k,n);
writeln(((x mod n)+(((m mod n)*c) mod n)) mod n);
end. -
02015-10-21 15:41:23@
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n,m,k,x,i,ans;
scanf("%d %d %d %d",&n,&m,&k,&x);
for(i=1;i<=k;i++)
m=m*10;
ans=(i+m)%n;
printf("%d",ans);
return 0;
} -
02015-10-08 22:12:07@
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int n,m,k,x,ans;
int Quick(int k){
int tmp=1;
if (k%2)tmp=10;
if (k==1)return 10;
k/=2;
tmp=(((tmp*Quick(k))%n)*Quick(k))%n;
return tmp;
}
int main(){
scanf("%d%d%d%d",&n,&m,&k,&x);
ans=Quick(k);
ans=(ans*m+x)%n;
cout<<ans<<endl;
} -
02015-10-08 15:07:36@
不知道怎么的就A了 只是模拟了一下 套了个快速幂而已
var
b:array[0..1000009] of boolean;
p,i,c,n,m,k,x:int64;
function jisuan(a,b,c:int64):int64;
var ans,d:int64;
begin
d:=a; ans:=1;
while b<>0 do
begin
if (b and 1=1) then ans:=(ans*d) mod c;
d:=(d*d) mod c;
b:=b>>1;
end;
exit(ans);
end;
begin
readln(n,m,k,x);
fillchar(b,sizeof(b),true);
i:=x;
while (b[i]=true) do
begin
b[i]:=false;
inc(c);
i:=i+m;
if i>n then i:=i-n;
end;
p:=jisuan(10,k,c);
c:=0;
while c<p do
begin
i:=i+m;
if i>n then i:=i-n;
inc(c);
end;
writeln(i);
end. -
02015-09-28 20:14:47@
#include<iostream>
#include<algorithm>
using namespace std;
long long n,m,x,k,i;
int main(){
cin>>n>>m>>k>>x;
long long ten=1,tmp=10;
while(k>0){
if(k%2)ten=(ten*tmp)%n;
k=k>>1;
tmp=(tmp*tmp)%n;
}
x=(x+ten*m)%n;
cout<<x;
} -
02015-09-11 21:31:10@
智商被辱
居然看错一点地方
WA了
唉 明明好水的嘛。 -
02015-08-23 13:42:35@
连个快速幂都写错我真是服了,wa2次
-
02015-08-11 23:59:50@
#include<iostream>
using namespace std;
long long PowerMod(int a,int b,int c)
{
int ans=1;
a=a%c;
while(b>0)
{
if(b%2==1)
ans=(ans*a)%c;
b=b/2;
a=(a*a)%c;
}
return ans;
}
int main()
{
long long n,m,k,x;
cin>>n>>m>>k>>x;
long long ans1=PowerMod(10,k,n)*m;
ans1=ans1%n;
cout<<(x+ans1)%n;
} -
02015-07-16 16:39:33@
#include<iostream>
long long n,m,k,x,ans,a=10;
int main()
{
std::cin>>n>>m>>k>>x;
for(ans=1;k;k/=2,a=(a*a)%n)
if(k%2) ans=(ans*a)%n;
std::cout<<(x+ans*m%n)%n;
}超级简单的快速幂,代码量只有9行
-
02015-06-04 13:44:09@
题目相当于\((x+m*10^k) \bmod {n}\)
快速幂和找环都可以,似乎还是快速幂快一些。C++ Code
#include <iostream> #include <cstring> using namespace std; long long power(int a,int b,int mod){ //快速幂 if (b==0) return 1; long long t=power(a,b/2,mod); t=(t*t)%mod; //n^2可能会爆int return (b%2)?(t*a)%mod:t; } int main(){ int n,m,k,x; cin >> n >> m >> k >> x; long long left=power(10,k,n)*m; //剩下的步数 left%=n; cout << (left+x)%n; }
-
02014-11-02 21:18:54@
那个字符好萌
-
02014-11-02 21:18:28@
P1841转圈游戏
Accepted记录信息
评测状态 Accepted
题目 P1841 转圈游戏
递交时间 2014-11-02 21:17:18
代码语言 C++
评测机 上海红茶馆
消耗时间 17 ms
消耗内存 560 KiB
评测时间 2014-11-02 21:17:20评测结果
编译成功
测试数据 #0: Accepted, time = 7 ms, mem = 560 KiB, score = 10
测试数据 #1: Accepted, time = 7 ms, mem = 556 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 556 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 552 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 556 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 556 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #8: Accepted, time = 3 ms, mem = 552 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 556 KiB, score = 10
Accepted, time = 17 ms, mem = 560 KiB, score = 100
代码
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>using namespace std;
int n , m , k , x;
unsigned long long exp( int a )
{
if( !a )
return 1;
if( a == 10 )
return 10 % n;
if( a & 1 )
return ( exp( a >> 1 ) * exp( a >> 1 ) * 10 ) % n;
return exp( a >> 1 ) * exp( a >> 1 ) % n;
}//
//
int main()
{
while( scanf( "%d %d %d %d" , &n , &m , &k , &x ) != EOF )
cout << ( exp( k ) * m + x ) % n << endl;
return 0;
} -
02014-11-02 21:07:12@
#include<iostream>
using namespace std;
long long qpow(long long a,long long b)
{
if(b==0)return 1;
long long r=qpow(a,b/2);
r*=r;
if(b%2)r*=a;
return r;
}
int main(){
int n,m,k,x;
long long ans=0;
cin>>n>>m>>k>>x;
ans+=qpow(10,k);
ans*=m;
ans+=x;
ans%=n;
cout<<ans<<endl;
return 0;
} 哪里错了,只过了3个点 -
02014-10-18 22:23:48@
考试时想复杂了,找了个环就退出。非常弱智啊。
-
02014-10-18 22:22:49@
#include <cstdio>
#include <cstring>int k;
long long ans;
int n,m,x;long long Exp(int y)
{
if(!y) return 1;
if(y==1) return 10%n;
if(y&1) return(((Exp(y>>1)*Exp(y>>1))%n)*10)%n;
else return(Exp(y>>1)*Exp(y>>1))%n;
}int main()
{
scanf("%d%d%d%d",&n,&m,&k,&x);
ans=Exp(k);
ans*=m;
ans%=n;
ans+=x;
ans%=n;
printf("%lld",ans);
return 0;
} -
02014-07-30 10:38:06@
Pascal:
var
n,m,k,x:int64;
ans:int64;
t:int64;
begin
readln(n,m,k,x);
t:=10;
ans:=1;
while k<>0 do
begin
if k mod 2=1
then ans:=ans*t mod n;
t:=t*t mod n;
k:=k div 2;
end;
ans:=ans*m mod n;
ans:=(ans+x) mod n;
writeln(ans);
end. -
02014-07-26 16:39:33@
犯傻了,硬套了原根进去,才发现看错题目
-
02014-02-18 19:17:10@
快速幂
-
02013-11-23 20:26:22@
var
n,m,k,x,ans,mi:qword;
function power(a,b,p:qword):qword;
var
tmp,res:qword;
begin
res:=1;
tmp:=a;
while b>0 do
begin
if b and 1=1 then res:=res*tmp mod p;
tmp:=tmp*tmp mod p;
b:=b shr 1;
end;
exit(res);
end;
begin
readln(n,m,k,x);
ans:=power(10,k,n);
ans:=(ans*m mod n+x) mod n;
writeln(ans);
end.快速幂。
信息
- ID
- 1841
- 难度
- 6
- 分类
- (无)
- 标签
- 递交数
- 6573
- 已通过
- 1791
- 通过率
- 27%
- 被复制
- 10
- 上传者