Created
February 16, 2014 14:34
-
-
Save kinaba/9035209 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
original = (<<'THE_END_OF_PICTURE'.split("\n").join("\n")+"\n").scan(/./m) - ["\n"] | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@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@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
@@@@@@@@11111111111111111111111111111111111111111111111111111111111111111@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
@@@@@@@@@@111111111111111111111111111111111111111111111111111111111111@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@111111111111111111111111111111111111111111111111111111111@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@111111111111111111111111111111111111111111111111111111@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@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@@@@@@@@@@@@@@@@@@@@@@@@@11111111111111@@@@@@@@@1111111111@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111111111@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111111111111@@@@@@@@@1111111111@@@@@@@@@@@@@@@@11@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111111111@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111111111111@@@@@@@@@1111111111@@@@@@@@@@@@@@1111@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111111111@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111111111111@@@@@@@@@1111111111@@@@@@@@@@@1@11111@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111111111@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111111111111@@@@@@@@@1111111111@@@@@@@@@@11111111@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111111111@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111111111111@@@@@@@@1111111111111@@@@11@111111111@@@@@@@@@@@@1@@@@@@@@@@@@1@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@1@@@@@@@@@@@@@@@@@@1@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111111111@@@@@@@@@@1@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111111111111@@@@@@@@@1111111111111111111111111111@@@@@@@@@@@111111111111@@111111111111111111111@@@@@@@@@@@11111111111111111111@@@@@@@@@@111111111111111111111111111111@@@@@@@@@@11111111111111111111@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111111111111@@@@@@@@@@@11111111111111111111111111@@@@@@@@@11111111111111@@1111111111111111111111@@@@@@@@@@@@111111111111111111111@@@@@@@111111111111111111111111111111@@@@@@@111111111111111111111@@@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111111111111@@@@@@@@@@@@@111111111111111111111111@@@@@@@1111111111111111@@111111111111111111111111@@@@@@@@@@@@11111111111111111111@@@@@@11111111111111111111111111111@@@@@1@111111111111111111111@@@@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111111111111@@@@@@@@@@@@@@@1111111111111111111111@@@@@111111111111111111@@11111111111111111111111111@@@@@@@@@@@@11111111111111111111@@@@111111111111111111111111111111@@@@11111111111111111111@@@@@@@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111111111111@@@@@@@@@1111111111111111111111111111@@@11111111111111111111@@1111111111111111111111111111@@@1@@1@@@@@11111111111111111111@@111111111111111111111111111111@@11111111111111111111@@1@@@@@1@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111111111111@@@@@@@@@1111111111@@@@@@@@@111111111@@@1111111111@@@@@@@@@@@@1111111111@@@@@@@@11111111111@@1111111111111@@@@@@1111111111@@1111111111@@@@@@@@@11111111111@@1111111111@@@@@@111111111111@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111111111111@@@@@@@@@1111111111@@@@@@@@@111111111@@@1111111111@@@@@@@@@@@@1111111111@@@@@@@@11111111111@@11111111111111@@@@@1111111111@@1111111111@@@@@@@@@11111111111@@1111111111@@@@11111111111111@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111111111111@@@@@@@@@1111111111@@@@@@@@@111111111@@@1111111111@@@@@@@@@@@@1111111111@@@@@@@@11111111111@@1111111111111111@@@1111111111@@1111111111@@@@@@@@@11111111111@@1111111111@@1111111111111111@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111111111111@@@@@@@@@1111111111@@@@@@@@@111111111@@@1111111111@@@@@@@@@@@@1111111111@@@@@@@@11111111111@@111111111111111111@1111111111@@1111111111@@@@@@@@@11111111111@@1111111111111111111111111111@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111111111111@@@@@@@@@1111111111@@@@@@@@@111111111@@@1111111111@@@@@@@@@@@@11111111111111111111111111111@@11111111111111111111111111111@@1111111111@@@@@@@@@11111111111@@111111111@11111111@111111111@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111111111111@@@@@@@@@1111111111@@@@@@@@@111111111@@@1111111111@@@@@@@@@@@@1111111111@111111111111111111@@1111111111@@@@@@@@@1111111111@@1111111111@@@@@@@@@11111111111@@1111111@1@@@@@@@@@@111111111@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111111111111@@@@@@@@@1111111111@@@@@@@@@111111111@@@1111111111@@@@@@@@@@@@1111111111@@@1111111111111111@@1111111111@@@@@@@@@1111111111@@1111111111@@@@@@@@@11111111111@@11111@@@@@@@@@@@@@@111111111@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111111111111@@@@@@@@@1111111111@@@@@@@@@111111111@@@1111111111@@@@@@@@@@@@1111111111@@@@@@1111111111111@@1111111111@@@@@@@@@1111111111@@1111111111@@@@@@@@@11111111111@@111@1@@@@@@@@@@@@@@111111111@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111111111111@@@@@@@@@1111111111@@@@@@@@@111111111@@@1111111111@@@@@@@@@@@11111111111@@@@@@@@11111111111@@1111111111@@@@@@@@@1111111111@@1111111111@@@@@@@@111111111111@@1@@@@@@@@@@@@@@@@@1111111111@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111111111111@@@@@@@@@@111111111@@@@@@@@@111111111@@@111111111@@@@@@@@@@@@@111111111111111111111@@@@@@@@@@11111111111111111111@@@@@@@@@@@@@1111111111111111111@1@@@@@@@@@@@@@@@1@111111111111111111111@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111111111111@@@@@@@@@@@@1111111@@@@@@@@@111111111@@@11111111@@@@@@@@@@@@@@@@111111111111111111111@@@@@@@@@@11111111111111111111@@@@@@@@@@@@@1111111111111111111@1@@@@@@@@@@@@@11111111111111111111@@@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111111111111@@@@@@@@@@@@@@11111@@@@@@@@@111111111@@@11111@@@@@@@@@@@@@@@@@@@@@111111111111111111111@@@@@@@@@@@1111111111111111111@@@@@@@@@@@@@1111111111111111111@@@@@@@@@@@11111111111111111111@@@@@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@111111111111111@@@@@@@@@@@@@@@111@@@@@@@@@111111111@@@1111@@@@@@@@@@@@@@@@@@@@@@@@111111111111111111111@@@@@@@@@@11111111111111111111@@@@@@@@@@@@@1111111111111111111@1@@@@@11111111111111111111@@@@@@@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@1@@@@@@@@@111111111@@@11@@@@@@@@@@@@@@@@@@@@@@@@@@@@111111111111111111111@@@@@@@@@@111111111111111111111@@@@@@@@@@@@1111111111111111111@@@11111111111111111111@@@@@@@@@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
THE_END_OF_PICTURE | |
def rle(a) | |
result = [] | |
until a.empty? | |
i = 0 | |
c = 0 | |
while i < a.size | |
if a[i] == a[0] | |
c += 1 | |
else | |
break | |
end | |
i += 1 | |
end | |
result << [a[0], c] | |
a = a[c..-1] | |
end | |
result | |
end | |
data = rle(original) | |
stat = data.group_by{|x|x[0]}.map{|k,v|[k,v.map{|a,b|b}.inject(&:+)]}.sort_by{|k,v|-v} | |
STDERR << "NSYM: " << stat.size << $/ | |
STDERR << "ORIGINAL: " << original.size << $/ | |
STDERR << stat.inspect << $/ | |
$bad = 0 | |
def strpush(str, c) | |
case c | |
when "\\".ord; $bad+=1; str << "\\\\" | |
when "\"".ord; $bad+=1; str << "\\\"" | |
when "\n".ord; $bad+=1; str << "\\n" | |
when "\r".ord; $bad+=1; str << "\\r" | |
else; str << c.chr | |
end | |
end | |
############################################################ | |
spec = Hash.new | |
spec["1"] = [1,4,7,11] | |
spec["@"] = [1,4,7,11] | |
bits = "" | |
data.each{|c,n| | |
x = spec[c] | |
if n <= (1<<x[0]) | |
prefix = "00" | |
rle_bits = x[0] | |
elsif n <= (1<<x[1]) | |
prefix = "01" | |
rle_bits = x[1] | |
elsif n <= (1<<x[2]) | |
prefix = "10" | |
rle_bits = x[2] | |
elsif n <= (1<<x[3]) | |
prefix = "11" | |
rle_bits = x[3] | |
else | |
STDERR.puts "OOPS" | |
end | |
bits += prefix | |
bits += "%0#{rle_bits}b" % (n-1) | |
} | |
STDERR << "EST: " << bits.size/8 << $/ | |
bits << "0"*(8-bits.size%8)%8 | |
ENCODED_LIT = (str = "" | |
for i in 0 ... bits.size/8 | |
strpush(str, bits[i*8 ... i*8+8].to_i(2)) | |
end | |
str | |
) | |
STDERR.puts "LIT :: #{ENCODED_LIT.size} bytes" | |
##################################################### | |
code = <<THE_END_OF_C | |
char*p="ENCODED_LIT"; | |
b,l,t=#{original.size},c,n; | |
r(n){ | |
for(l-=n;l<0;l+=8)b=b<<8|*p++&255; | |
return(1<<n)-1&b>>l; | |
} | |
main(){ | |
for(;t;) | |
for(c^=1,n=r("147;"[r(2)]-48)+1;n--;--t%246||puts("")) | |
putchar("1@"[c]); | |
} | |
THE_END_OF_C | |
code = code.gsub(/(?<!\w\w)\s*/,"") | |
code["ENCODED_LIT"] = ENCODED_LIT | |
STDERR.puts "#{code.size} bytes" | |
STDOUT.binmode | |
print code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define L ( | |
#define R ) | |
#define LP { | |
#define RP } | |
main L c, n R | |
LP | |
while L | |
L ~scanf L "%d",&n R R | |
&&! | |
L c || printf L "%lld\n", 1LL*n*-~n/2 R, c=0 R | |
R | |
LP RP | |
while L exit L 0 R, 1 R LP RP | |
RP | |
/* | |
main(c,n) | |
{ | |
while(~scanf("%d",&n)) | |
c || printf("%lld\n", 1LL*n*-~n/2), c=0; | |
return 0; | |
} | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a;main(){a=!puts("Threads 2k14");} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
using namespace std; | |
typedef long long LL; | |
LL powmod(LL a, LL b, LL m) { | |
LL x = 1; | |
for(; b; b>>=1) { | |
if(b&1) | |
x = __uint128_t(x)*a % m; | |
a = __uint128_t(a)*a % m; | |
} | |
return x; | |
} | |
bool Fermat(int b, LL n) { | |
return powmod(b, n-1, n) == 1; | |
} | |
bool MillerRabin(int b, LL n) { | |
if(n%b == 0) | |
return false; | |
LL u = n-1; | |
int t = 0; | |
while((u&1)==0) | |
t++, u>>=1; | |
LL x = powmod(b, u, n); | |
if(x == 1) | |
return true; | |
for(int i=0; i<t; ++i) { | |
if(x==n-1) | |
return true; | |
x = __uint128_t(x)*x % n; | |
} | |
return false; | |
} | |
int main() | |
{ | |
int cnt=5; | |
puts("2"); | |
puts("3"); | |
puts("5"); | |
puts("7"); | |
puts("11"); | |
static const int tt[]={3,7,9,1}; | |
for(int td=10; td<=10000000; td*=10) | |
for(int t=0; t<sizeof(tt)/sizeof(*tt); ++t) | |
for(int vv=0; vv<td; ++vv) | |
{ | |
int v = td*tt[t] + vv; | |
LL z = v; | |
for(int u=v/10; u; u/=10) | |
z = z*10 + u%10; | |
if(z%3 && z%7 && z%11 && z%13 && z%17 && MillerRabin(31,z)) | |
printf("%lld\n",z); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
code = 'n=\'d%\';main(s){for(scanf(&n,&n);n--;)printf(s=@ME@,34,s);n=!puts(s-1);}' | |
code = code.sub("@ME@", '"' + code.sub("@ME@", "%c%s%1$c") + '"') | |
STDOUT.binmode | |
STDOUT.puts code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_$,_$$,_$$$,_$$$$['$'*'$'*'$']; | |
_$$$$$(){_$$=_$$$=!gets(_$$$$);} | |
_$$$$$$(){ | |
_$ = _$$$$[_$$/('$'-' ')] >> _$$%('$'-' ')*('('-' ') & -~'~'; | |
_$$++; | |
} | |
__ = '*'+'/'; | |
___ = ' '+'.'; | |
____(_){ | |
_$$$$$$(); | |
_$$$ || ____( | |
_$=='@'+'!' ? "%&%'("[_-'$'] | |
: _$=='@'+'"' ? "'$&'("[_-'$'] | |
: _$ ? "''''("[_-'$'] | |
: (_=='(' || puts(_=='&' ? &__ : &___), _$$$$$(), '$') | |
); | |
} | |
main(){ | |
_$$$$$(); | |
__ = !____('('); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
code = <<'__CODE__' | |
long long u['~~~'],v['~~~'],w,x; | |
main(y,z){ | |
for(gets(&y);~scanf("%d",&y);x=0){ | |
for(z=y;z--;z&=-~z) | |
x+=u[z],w+=v[z]; | |
for(;y<2e5;y|=-~y) | |
u[y]++,v[y]+=x; | |
} | |
w=!printf("%lld\n",w); | |
} | |
__CODE__ | |
LIMIT = 50000 | |
code = code.gsub(/[\n\t]/,"") | |
glue = "\n" | |
extra = "//" | |
chars = (0..126).map{|c| "%c"%c} - [" ","\t","\n","\r"] | |
n = (LIMIT - code.size - extra.size - glue.size)/chars.size | |
chars.each{|c|n.times{extra<<c}} | |
extra<<'~' while code.size+extra.size+glue.size<LIMIT | |
STDOUT.binmode | |
print extra+glue+code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment