generated from sigonasr2/CPlusPlusProjectTemplate
This isn't the one..
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
dc6f9e07c7
commit
4014ee0343
Binary file not shown.
89
main.cpp
89
main.cpp
@ -29,27 +29,58 @@ std::vector<int>factor(int numb){
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct factorNumber{
|
struct factorNumber{
|
||||||
void SetupOffsets(){
|
void SetupOffsets(int initial){
|
||||||
offsets.push_back({23,0});
|
offsets.push_back({23,0});
|
||||||
offsets.push_back({19,0});
|
offsets.push_back({19,0});
|
||||||
offsets.push_back({13,0});
|
offsets.push_back({13,0});
|
||||||
offsets.push_back({17,0});
|
offsets.push_back({17,0});
|
||||||
|
for (int i=0;i<offsets.size();i++){
|
||||||
|
offsets[i].second=initial%offsets[i].first;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
std::vector<int>factors;
|
std::vector<std::pair<int,int>>factors;
|
||||||
std::vector<std::pair<int,int>>offsets;
|
std::vector<std::pair<int,int>>offsets;
|
||||||
factorNumber(int numb){
|
factorNumber(int numb){
|
||||||
SetupOffsets();
|
SetupOffsets(numb);
|
||||||
|
std::vector<int>tmp=factor(numb);
|
||||||
|
for (int j=0;j<tmp.size();j++){
|
||||||
|
for (int i=0;i<factors.size();i++){
|
||||||
|
if (factors[i].first==tmp[j]){
|
||||||
|
factors[i].second++;
|
||||||
|
goto nextfactor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
factors.push_back({tmp[j],1});
|
||||||
|
nextfactor:;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
factorNumber&operator=(int numb){
|
factorNumber&operator=(int numb){
|
||||||
factors.clear();
|
factors.clear();
|
||||||
offsets.clear();
|
offsets.clear();
|
||||||
SetupOffsets();
|
SetupOffsets(numb);
|
||||||
factors=factor(numb);
|
std::vector<int>tmp=factor(numb);
|
||||||
|
for (int j=0;j<tmp.size();j++){
|
||||||
|
for (int i=0;i<factors.size();i++){
|
||||||
|
if (factors[i].first==tmp[j]){
|
||||||
|
factors[i].second++;
|
||||||
|
goto nextfactor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
factors.push_back({tmp[j],1});
|
||||||
|
nextfactor:;
|
||||||
|
}
|
||||||
return*this;
|
return*this;
|
||||||
}
|
}
|
||||||
factorNumber&operator+=(int numb){
|
factorNumber&operator+=(int numb){
|
||||||
for (int i=0;i<offsets.size();i++){
|
for (int i=0;i<offsets.size();i++){
|
||||||
std::pair<int,int>&offset=offsets[i];
|
std::pair<int,int>&offset=offsets[i];
|
||||||
|
for (int j=0;j<factors.size();j++){
|
||||||
|
if (factors[j].first==offset.first){
|
||||||
|
factors[j].second+=(offset.second+numb)/offset.first;
|
||||||
|
goto addOffset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addOffset:
|
||||||
offset.second=(offset.second+numb)%offset.first;
|
offset.second=(offset.second+numb)%offset.first;
|
||||||
}
|
}
|
||||||
return*this;
|
return*this;
|
||||||
@ -58,11 +89,12 @@ struct factorNumber{
|
|||||||
std::vector<int>factors=factor(numb);
|
std::vector<int>factors=factor(numb);
|
||||||
for (int i=0;i<factors.size();i++){
|
for (int i=0;i<factors.size();i++){
|
||||||
for (int j=0;j<this->factors.size();j++){
|
for (int j=0;j<this->factors.size();j++){
|
||||||
if (this->factors[j]==factors[i]){
|
if (this->factors[j].first==factors[i]){
|
||||||
|
this->factors[j].second++;
|
||||||
goto gonext;
|
goto gonext;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this->factors.push_back(factors[i]);
|
this->factors.push_back({factors[i],1});
|
||||||
gonext:;
|
gonext:;
|
||||||
}
|
}
|
||||||
return*this;
|
return*this;
|
||||||
@ -70,22 +102,28 @@ struct factorNumber{
|
|||||||
int operator%(int numb){
|
int operator%(int numb){
|
||||||
for (int i=0;i<offsets.size();i++){
|
for (int i=0;i<offsets.size();i++){
|
||||||
if (offsets[i].first==numb){
|
if (offsets[i].first==numb){
|
||||||
if (offsets[i].second==0) {
|
return offsets[i].second;
|
||||||
for (int j=0;j<factors.size();j++){
|
}
|
||||||
if (factors[j]==numb){
|
}
|
||||||
return 0;
|
for (int j=0;j<factors.size();j++){
|
||||||
}
|
if (factors[j].first!=1&&(factors[j].first==numb||factors[j].second%numb==0)){
|
||||||
}
|
return 0;
|
||||||
//std::cout<<"Not divisible!"<<std::endl;
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
return offsets[i].second;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout<<"No divisibility information for modulus "<<numb<<" !! THIS SHOULDN'T BE HAPPENING !!"<<std::endl;
|
std::cout<<"No divisibility information for modulus "<<numb<<" !! THIS SHOULDN'T BE HAPPENING !!"<<std::endl;
|
||||||
return -1; //This shouldn't happen??
|
return -1; //This shouldn't happen??
|
||||||
}
|
}
|
||||||
|
friend std::ostream&operator<<(std::ostream&out,factorNumber&rhs){
|
||||||
|
out<<"Factors:"<<std::endl;
|
||||||
|
for (int i=0;i<rhs.factors.size();i++){
|
||||||
|
out<<" "<<rhs.factors[i].first<<" x"<<rhs.factors[i].second<<std::endl;
|
||||||
|
}
|
||||||
|
std::cout<<"Offsets:"<<std::endl;
|
||||||
|
for (int i=0;i<rhs.offsets.size();i++){
|
||||||
|
out<<" "<<rhs.offsets[i].first<<": "<<rhs.offsets[i].second<<std::endl;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Monkey{
|
struct Monkey{
|
||||||
@ -116,6 +154,20 @@ int main()
|
|||||||
monkeys.push_back({{79, 60, 97},'*',-1,13,1,3});
|
monkeys.push_back({{79, 60, 97},'*',-1,13,1,3});
|
||||||
monkeys.push_back({{74},'+',3,17,0,1});
|
monkeys.push_back({{74},'+',3,17,0,1});
|
||||||
|
|
||||||
|
/*
|
||||||
|
factorNumber test(17);
|
||||||
|
|
||||||
|
test=84075;
|
||||||
|
for (int i=0;i<77;i++){
|
||||||
|
test*=23;
|
||||||
|
}
|
||||||
|
std::cout<<test<<std::endl;
|
||||||
|
std::cout<<test%59<<std::endl;
|
||||||
|
std::cout<<test%19<<std::endl;
|
||||||
|
std::cout<<test%23<<std::endl;
|
||||||
|
std::cout<<test%13<<std::endl;
|
||||||
|
std::cout<<test%17<<std::endl;*/
|
||||||
|
|
||||||
for (int round=0;round<10000;round++){
|
for (int round=0;round<10000;round++){
|
||||||
for (int i=0;i<monkeys.size();i++){
|
for (int i=0;i<monkeys.size();i++){
|
||||||
Monkey&m=monkeys[i];
|
Monkey&m=monkeys[i];
|
||||||
@ -164,5 +216,6 @@ int main()
|
|||||||
|
|
||||||
std::cout<<((long)monkeys[0].inspAmt*(long)monkeys[1].inspAmt)<<std::endl;
|
std::cout<<((long)monkeys[0].inspAmt*(long)monkeys[1].inspAmt)<<std::endl;
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user