406 - Prime Cuts
Posted: Tue May 17, 2005 6:44 pm
I can't understand the problem 406(Prime Cuts).Can anybody tell me what to do?Plz help me.
Code: Select all
21 2
18 2
523 40
18 18
100 7
1000 25
1000 12
523 40
12 10
21 3
99 25
100 100
723 12
Code: Select all
21 2 : 5 7 11
18 2 : 3 5 7 11
523 40 : 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461
18 18 : 1 2 3 5 7 11 13 17
100 7 : 13 17 19 23 29 31 37 41 43 47 53 59 61 67
1000 25 : 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593
1000 12 : 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499
523 40 : 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461
12 10 : 1 2 3 5 7 11
21 3 : 3 5 7 11 13
99 25 : 1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
100 100 : 1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
723 12 : 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379
Code: Select all
21 2 : 5 7 11
18 2 : 3 5 7 11
523 40 : 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461
18 18 : 1 2 3 5 7 11 13 17
100 7 : 13 17 19 23 29 31 37 41 43 47 53 59 61 67
1000 25 : 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601
1000 12 : 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509
523 40 : 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461
12 10 : 1 2 3 5 7 11
21 3 : 3 5 7 11 13
99 25 : 1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
100 100 : 1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
723 12 : 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379
723 12 : 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379
Code: Select all
18 18: 1 2 3 5 7 11 13 17
(blank line)
// that means should I use cout << answer << endl << endl;
Code: Select all
18 18: 1 2 3 5 7 11 13 17 // that means should I use cout << answer << endl;?
Code: Select all
#include <iostream>
#define no_prime 10000
#define no_input 500
using namespace std;
int main(){
int temp[no_prime];
int store_n[no_input];
int store_c[no_input];
int count=0;
int n;
int c;
while(cin >> n >>c){
store_n[count]=n;
store_c[count]=c;
count++;
}
for(int k=0;k<count;k++){
int temp_count=0;
int isPrime =1;
cout << store_n[k] << " " << store_c[k] << ": ";
// cout <<": ";
for(int i=1;i<=store_n[k];i++,isPrime=1){
for(int j=2;j<i;j++){
if((i%j)==0&&i!=j){
isPrime=0;
break;
}
}
if(isPrime==1){
//cout << i << " ";
temp[temp_count]=i;
temp_count++;
}
}
if(store_c[k]<temp_count){
if(temp_count%2==0){//even range= temp_count/2+1 -c to temp_count/2+1 +c
temp_count=temp_count/2;
for(int i=temp_count-store_c[k];i<temp_count+store_c[k];i++){
cout<< temp[i] << " ";
}
cout << endl;
}else{//odd range =temp_count/2
temp_count=temp_count/2;
for(int i=temp_count-store_c[k]+1;i<temp_count+store_c[k];i++){
cout << temp[i]<< " ";
}
cout << endl;
}
}else{//print out all if c >= temp_count
for(int i=0;i<temp_count;i++){
cout<< temp[i] << " ";
}
cout << endl;
}
cout << endl;
}
return 0;
}
Code: Select all
#include <iostream>
#define no_prime 1000
using namespace std;
int main(){
int temp[no_prime];
int n;
int c;
while(cin){
cin >> n >> c;
int temp_count=0;
int isPrime =1;
cout << n << " " << c << " : ";
//cout << "\b: " ;
for(int i=1;i<=n;i++,isPrime=1){
for(int j=2;j<i;j++){
if((i%j)==0&&i!=j){
isPrime=0;
break;
}
}
if(isPrime==1){
//cout << i << " ";
temp[temp_count]=i;
temp_count++;
}
}
if(c<temp_count){
if(temp_count%2==0){//even range= temp_count/2+1 -c to temp_count/2+1 +c
temp_count=temp_count/2;
for(int i=temp_count-c;i<temp_count+c;i++){
cout<< temp[i] << " ";
}
cout << endl;
}else{//odd range =temp_count/2
temp_count=temp_count/2;
for(int i=temp_count-c+1;i<temp_count+c;i++){
cout << temp[i]<< " ";
}
cout << endl;
}
}else{//print out all if c >= temp_count
for(int i=0;i<temp_count;i++){
cout<< temp[i] << " ";
}
cout << endl;
}
}
return 0;
}
Code: Select all
997 1
Code: Select all
433
Code: Select all
900 79
Code: Select all
900 79: 1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887
Code: Select all
18 18: 1 2 3 5 7 11 13 17
(blank line)
// that means should I use cout << answer << endl << endl; Yes is the answer
Code: Select all
cout << n << " " << c << " : "; //Your code
cout << n << " " << c << ":"; //Should be
Code: Select all
cout<< temp[i] << " "; //your code
cout<< " " <<temp[i] ; //should be
Nice English!!!kolpobilashi wrote:i got TLE 4 dis code,and cant get the reason, anybody tell me y n wats de solution.....![]()
Code: Select all
for(i=0;i<=1003;i++)
ch1[i]=isPrime(i);