#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
long long int read(long long int a){
a=0;
char c='0';
while(c>='0'&&c<='9'){
a=a*10+c-'0';
c=getchar();
}
return a;
}
void write(long long int d){
if(d==0){
putchar(48);
return;
}
int len=0;
char n[20];
while(d>0){
n[len]=d%10+48;
len++;
d/=10;
}
for(int i=len-1;i>=0;i--) putchar(n[i]);
}
int main(){
long long int a,b,c;
while(a=read(a),b=read(b),c=read(c)){
long long int d[c];
c-=1;
d[c]=a;
while(c--){
d[c]=d[c+1]*d[c+1]%b;
write(d[c+1]);
putchar(32);
}
write(d[c+1]);
puts("\n");
}
}
#include
#include
#include
using namespace std;
long long int read(long long int a){
a=0;
char c='0';
while(c>='0'&&c<='9'){
a=a*10+c-'0';
c=getchar();
}
return a;
}
void write(long long int d){
if(d==0){
putchar(48);
return;
}
int len=0;
char n[20];
while(d>0){
n[len]=d%10+48;
len++;
d/=10;
}
for(int i=len-1;i>=0;i--) putchar(n[i]);
}
int main(){
long long int a,b,c;
while(a=read(a),b=read(b),c=read(c)){
long long int d[c];
c-=1;
d[c]=a;
while(c--){
d[c]=d[c+1]*d[c+1]%b;
write(d[c+1]);
putchar(32);
}
write(d[c+1]);
puts("\n");
}
}
我已經盡力優化了,還是90%(29ms/0.4s/TLE/0.2s)
#include<ios>
inline long long read(){
register long long a=0;
register char c=getchar();
do{
a=(a<<3)+(a<<1)+c-48;
c=getchar();
}while(c>=48&&c<=57);
return a;
}
inline void write(register long long d){
if(d==0){
putchar(48);
return;
}
register int len=0;
register char n[20];
while(d>0){
n[len]=d%10+48;
len++;
d/=10;
}
for(register int i=len-1;i>=0;i--)putchar(n[i]);
}
int main(){
register long long a,b,c;
while(a=read(),b=read(),c=read()){
write(a);
c--;
while(c--){
a=a*a%b;
putchar(32);
write(a);
}
puts("");
}
}
之後看到題主的blog才AC:http://morris821028.github.io/2015/06/26/zj-b415/
看起來還是題主比較厲害,各方面都優化到了