1 条题解
-
0
C++ :
#include<cstdio> #include<algorithm> using namespace std; #define F(x) for(int x=0;x<=1;x++) int n,i,j,k,l,m,o,p,q,w,e; long long ans=99999999999999999; int main() { bool t=true; scanf("%d",&n); F(i) F(j) F(k) F(l) F(m) F(e) F(o) F(p) F(q) F(w) F(i1) F(i2) F(i3) F(i4) F(i5) F(i6) F(i7) F(i8) F(i9) { long long temp=1*i+10*j+100*k+1000*l+10000*m+100000*e+1000000*o+10000000*p+100000000*q+1000000000*w; long long temp2=10000000000*i1+100000000000*i2+1000000000000*i3+10000000000000*i4+100000000000000*i5+1000000000000000*i6+10000000000000000*i7+100000000000000000*i8+1000000000000000000*i9; temp+=temp2; if(temp%n==0 and temp!=0) { ans=min(ans,temp/n); t=false; } } if(!t) printf("%lld\n",ans); else printf("No Solution\n"); }Pascal :
const maxn=100100; var n,len,i,j,yu,t:longint; f:array[0..maxn]of boolean; bfs:array[1..maxn,1..3]of longint; find:boolean; mul:array[0..maxn]of longint; ch:char; begin readln(n); if n=1 then writeln(1) else begin fillchar(f,sizeof(f),false); fillchar(bfs,sizeof(bfs),0); f[1]:=true; len:=1; bfs[len,1]:=1;bfs[len,2]:=1;bfs[len,3]:=0; find:=false; i:=0; repeat inc(i); for j:=0 to 1 do begin yu:=(bfs[i,2]*10+j)mod n; if not f[yu] then begin inc(len); f[yu]:=true; bfs[len,1]:=j; bfs[len,2]:=yu; bfs[len,3]:=i; if yu=0 then begin find:=true; break; end; end; end; if find then break; until i=len; if not find then writeln('No Solution') else begin mul[0]:=0; i:=len; while i<>0 do begin inc(mul[0]); mul[mul[0]]:=bfs[i,1]; i:=bfs[i,3]; end; yu:=0; for i:=mul[0] downto 1 do begin t:=yu*10+mul[i]; mul[i]:=t div n; yu:=t mod n; end; while mul[mul[0]]=0 do dec(mul[0]); for i:=mul[0] downto 1 do write(mul[i]); writeln; end; end; end.
- 1
信息
- ID
- 3532
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者