Jump to content
GIGN Forum

Atrodi Īsto


Sebis
 Share

Recommended Posts

  • Replies 58
  • Created
  • Last Reply

Top Posters In This Topic

1)

A high school has a strange principal. On the first day, he has his students perform an odd opening day ceremony:

There are one thousand lockers and one thousand students in the school. The principal asks the first student to go to every locker and open it. Then he has the second student go to every second locker and close it. The third goes to every third locker and, if it is closed, he opens it, and if it is open, he closes it. The fourth student does this to every fourth locker, and so on. After the process is completed with the thousandth student, how many lockers are open?

Es esmu slinks...

#include <iostream>
using namespace std;

int main(){

int locker[1001];
int counter=0;

for(int i=1; i<1002; i++){
    locker[i]=0;
}
for(int i=1; i<1002;i++){
    for(int j=i;j<1002;j=j+i){
        if(locker[j]==0) locker[j]=1;
        else locker[j]=0;
    }
}
for(int i=1; i<1002; i++){
    if(locker[i]==1) counter++;
    cout<<locker[i]<<" ";
}
cout<<'\n'<<counter<<'\n';
return 0;
}

Link to comment
Share on other sites

1, 5, 32, 288, 3413, 50069

Man pēdējam uzdevumam vajag kādu ierobežojošu faktoru (piemēram, katru nākamo virknes locekli vai iegūt no iepriekšējā vai ko tādu). Citādi es pieņemu, ka atrisinājums ir šāds: pirmie trīs virknes locekļi ir definēti (100, 121, 144) un katru nākamo var aprēķināt pēc formulas a(n) = a(n-3)*2+2

Link to comment
Share on other sites

Tur nekas nav tā pat vien definēts. Nākošo var atrast, atrodot sakarību starp iepriekšējiem.

Atbilde ir pareiza, risinājums gan uzrādīts savādāks.

Solution:

1 = 1^1

5 = 1^1 + 2^2

32 = 1^1 + 2^2 + 3^3

288 = 1^1 + 2^2 + 3^3 + 4^4

3413 = 1^1 + 2^2 + 3^3 + 4^4 + 5^5

50069 = 1^1 + 2^2 + 3^3 + 4^4 + 5^5 + 6^6

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share


×
×
  • Create New...