初音ミクの消失

nisc-src_leak

字数统计: 757阅读时长: 4 min
2019/08/18 Share

src_leak

src_leak_2886f9ce0464ae67bbeb52d939c9979d.zip

没学过c++语法,看这些东西看蒙了

就大概猜了一下,发现算法流程并不是很复杂

x1~x5都是用一个函数跑出来的

x6用另一个

cout << func3< func2<x1> > << endl;
cout << func3< func2<x2> > << endl;
cout << func3< func2<x3> > << endl;
cout << func3< func2<x4> > << endl;
cout << func3< func2<x5> > << endl;

// output: 1 1 1 1 1


cout << _func1<x1>::result << endl;
cout << _func1<x2>::result << endl;
cout << _func1<x3>::result << endl;
cout << _func1<x4>::result << endl;
cout << _func1<x5>::result << endl;

//output: 963 4396 6666 1999 3141

说几个比较关键的地方

template <bool Flag, class MaybeA, class MaybeB> class IfElse;

template <class MaybeA, class MaybeB>
class IfElse<true, MaybeA, MaybeB> {
public:
using ResultType = MaybeA;
};

template <class MaybeA, class MaybeB>
class IfElse<false, MaybeA, MaybeB> {
public:
using ResultType = MaybeB;

看起来这么大一堆,实际上就表达了一个意思

result = flag ? MaybeA:MaybeB

template <uint N, uint L> struct func1<N, L, L> { enum { result = L }; };

template<>
constexpr size_t func2<0> = 0;

template<uint m>struct TEST<0, m> {
const static uint value = 0;
};

template<uint n>struct TEST<n, 0> {
const static uint value = 1;
};

template<>struct func4<1> {
const static uint value = 0;
};
template<>struct func4<2> {
const static uint value = 1;
};

以上是各个函数的边界条件,一定不能省略,否则跑不出来或者跑出来不对,尤其是func4的1和2

因为c的执行效率比较高,抱着试一试的心态,写了个暴力算法进行求解,在int范围下尝试失败(因为涉及到了数据的平方,int类型会溢出),于是更换为long long 进行求解,虽然效率不高,但还是可以在十秒中左右得出结果。

#include<cstdio>
typedef long long LL;

LL func2(LL n){
if(n==0) return 0;

return n%2 + func2(n/2);
}

LL func3(LL n){
return n%2;
}


LL func1(LL n, LL l, LL r){
if(l==r) return l;
LL mid = (l+r+1)/2;
if(n < mid*mid)
return func1(n,l,mid-1);
else
return func1(n,mid,r);
}

LL _func1(LL n){
return func1(n,1,n);
}

LL nextn(LL n, LL m){
return ((n % m != 0) * n);
}

LL nextm(LL n, LL m){
return (m * m <= n ? (m + 1) : 0);
}

LL test(LL n,LL m){
if(n == 0) return 0;
if(m == 0) return 1;
return test(nextn(n,m) , nextm(n,m));
}

LL func4(LL n){
if(n==1) return 0;
if(n==0) return 1;
return test(n,2);
}

int main(){

/************
x1 ~ x5

//input: 963 4396 6666 1999 3141

// ans = 1927 8792 13332 3998 6282

**********/
LL input[] = {963,4396,6666,1999,3141};
printf("flag{");
for(LL j = 0; j<=4 ; j++){
LL ans = input[j];
for(LL i=0;i<=300000000;i++){
if(func3(func2(i))==1)
if(_func1(i) == ans){
printf("%lld",i);
break;
}
/* if(i % 100000 == 0)
printf("%d finished\n",i);*/
}
printf("-");
}

/************
x6 = 1229


**********/

LL cnt=1;
for(LL i=3;i<=10000;i++)
if(func4(i)==1)
cnt++;
printf("%lld}",cnt);


//flag{927369-19324816-44435556-3996001-9865881-1229}
}

原文作者:mrh929

原文链接:https://mrh1s.top/posts/9455f959/

发表日期:August 18th 2019, 6:44:38 pm

更新日期:August 18th 2019, 6:49:29 pm

版权声明:本文采用知识共享署名-非商业性使用 4.0 国际许可协议进行许可

CATALOG
  1. 1. src_leak