正规数的判定,减少运行时间

问题遇到的现象和发生背景

题目描述
如果一个正整数的所有素因子均不超过 55,则它被称为正规数(Regular Number)。例如 60是一个正规数,因为 60=2^2*3。前十五个正规数为:
1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24

给定一个正整数 n,请判定它是否是一个正规数。

输入格式
单个正整数:表示 n。

输出格式
如果 n 是正规数,输出 Regular Number;
如果不是,输出 Irregular Number

问题相关代码,请勿粘贴截图
#include <iostream>
using namespace std;

int main()
{
    int n,s;
    cin>>n;
    int p=2;
    while(n>1){
        if(n%p==0){
            n=n/p;
            s=p;
        }
       else
       p++;
    }
    if(s<=5)
        cout<<"Regular Number";
    
    else cout<<"Irregular Number";
    
      
    return 0;
}

运行结果及报错内容

超时

我想要达到的结果

减少运行时间

供参考:

#include <iostream>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    while(n%2==0) n/=2;
    while(n%3==0) n/=3;
    while(n%5==0) n/=5;
    if(n==1)
       cout<<"Regular Number"<<endl;
    else
       cout<<"Irregular Number"<<endl;
    return 0;
}