Advertisement
anhkiet2507

UOC SO NGUYEN TO NHO NHAT

Aug 29th, 2021
2,524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3. using namespace std;
  4. int ktnt(long long a){
  5.     if(a==2){
  6.         return 1;
  7.     }
  8.     if(a<2||a%2==0){
  9.         return 0;
  10.     }
  11.     for(int i=3;i<=sqrt(a);i+=2){
  12.         if(a%i==0){
  13.             return i;
  14.             break;
  15.         }
  16.     }
  17.     return 1;
  18. }
  19. int main(){
  20.     int t;
  21.     cin >> t;
  22.     while(t--){
  23.         long long n,i;
  24.         cin >> n;
  25.         cout << 1 << " ";
  26.         for(i = 2; i<=n; i++){
  27.             if(i%2==0){
  28.                 cout << 2 << " ";
  29.             }else{
  30.                 if(ktnt(i)==1){
  31.                     cout << i << " ";
  32.                 }else{
  33.                     cout << ktnt(i) << " ";
  34.                 }
  35.             }
  36.         }
  37.         cout << endl;
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement