This commit is contained in:
Zengtudor 2024-11-28 09:56:22 +08:00
parent 4d387280dc
commit 7ceea85559
2 changed files with 80 additions and 68 deletions

61
src/11/27/P7960.cpp Normal file
View File

@ -0,0 +1,61 @@
#include <bitset>
#include <cstdint>
#include <iostream>
using namespace std;
using ll = int64_t;
ll const maxx{ll(1e6+5)};
ll t,x,minPrim[maxx],isSeven[maxx];
bitset<maxx>isPrim;
void initPrim(){
isPrim.set();
for(ll i{2};i<=maxx;i++){
if(isPrim[i]){
for(ll j{i+i};j<=maxx;j+=i){
isPrim[j]=false;
if(!minPrim[j]){
minPrim[j]=i;
}
}
}
}
}
bool check(ll const& num){
if(isSeven[num]!=0)return isSeven[num]==-1?false:true;
ll tmp{num};
while(tmp!=0){
if(tmp%10==7){
isSeven[num]=true;
return true;
}
}
isSeven[num]=-1;
return false;
}
int main(){
ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
initPrim();
for(ll i{1};i<=10;i++){
cout<<isPrim[i]<<' ';
}
cout<<'\n';
for(ll i{1};i<=10;i++){
cout<<minPrim[i]<<' ';
}
cout<<'\n';
cin>>t;
while(t--){
cin>>x;
while(x!=0){
if(check(minPrim[x])){
}
}
}
}

View File

@ -1,71 +1,22 @@
#include <array>
#include <cstdint>
#include <iostream>
#include <random>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <utility>
#include <variant>
using namespace std;
using ll = int64_t;
template<class T,class P>
ostream&operator<<(ostream&os,pair<T,P>const&p){
os<<"( "<<p.first<<", "<<p.second<<" )";
return os;
}
variant<ll,string> test(){
random_device v;
mt19937 mt(v());
uniform_int_distribution<short> un(0,50);
ll number{un(mt)};
if(!number){
return "Zengtudor";
}
return number;
}
template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
template<class T,class ...Args>
struct Array{
static constexpr ll size(){return sizeof...(Args)+1;}
decay_t<T> arr[size()];
Array(T const&t, Args const&...args){
arr[0]=t;
ll idx{1};
((arr[idx++]=args),...);
}
friend ostream&operator<<(ostream&os,Array const&arr){
os<<"[ ";
for(ll i{0};i<size();i++){
os<<arr.arr[i]<<" ,";
}
cout<<" ]";
return os;
}
};
// template<class T,class ...Args>
// Array(T,Args...)->Array<T,Args...>;
#include <memory>
int main(){
array<int,2> a{};
for(auto const& i:a)cout<<i<<" ";
cout<<'\n';
Array arr {1,2,3};
cout<<arr<<'\n';
// cout<<sizeof(test())<<'\n';
// ll n{100};
// // cin>>n;
// while(n--){
// cout<<visit(overloaded{
// [](string const&str){cout<<"is str\n";throw runtime_error("throwing error");return 1;},
// [](ll const& n){cout<<"is number\n";return 2;}
// },test())<<"\n";
// }
using namespace std;
struct X{
X(int const& x){cout<<"X is constructing: "<<x<<'\n';}
~X(){cout<<"X is dead\n";}
};
struct T{
T():t{1}{};
int t;
};
auto b = make_unique<X>(1);
int t{5};
while(t--){
T t;
cout<<t.t<<'\n';
}
cout<<"retrun 0;\n";
return 0;
}