NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

LightOJ 1045
------------------
#include<bits/stdc++.h>
using namespace std;

#define read(f) freopen(f, "r", stdin)
#define write(f) freopen(f, "w", stdout)

#define mms(x,y) memset(x, y, sizeof x)
#define CLR(x) memset(x, 0, sizeof x)
#define LLU unsigned long long
#define LLI long long
#define LI long

#define get(x) getline(cin,str)
#define ws() cin>>ws

#define in(x) cin>>x
#define in2(x,y) cin>>x>>y
#define in3(x,y,z) cin>>x>>y>>z
#define in4(w,x,y,z) cin>>w>>x>>y>>z

#define out(x) cout << x
#define out2(x,y) cout << x << " " << y
#define out3(x,y,z) cout << x << " " << y << " " << z
#define out4(w,x,y,z) cout << w << " " << x << " " << y << " " << z

#define pri(x) printf("%dn",x)
#define pri2(x,y) printf("%d %dn",x,y)
#define pri3(x,y,z) printf("%d %d %dn",x,y,z)
#define pri4(w,x,y,z) printf("%d %d %d %dn",w,x,y,z)

#define prLI(x) printf("%ldn",x)
#define prLI2(x,y) printf("%ld %ldn",x,y)
#define prLI3(x,y,z) printf("%ld %ld %ldn",x,y,z)
#define prLI4(w,x,y,z) printf("%ld %ld %ld %ldn",w,x,y,z)

#define prs(x) printf(x)

#define el << 'n'

#define sci(x) scanf("%d", &x)
#define sci2(x,y) scanf("%d %d", &x, &y)
#define sci3(x,y,z) scanf("%d %d %d", &x, &y, &z)
#define sci4(w,x,y,z) scanf("%d %d %d %d", &w, &x, &y, &z)

#define scLI(x) scanf("%ld", &x)
#define scLI2(x,y) scanf("%ld %ld", &x, &y)
#define scLI3(x,y,z) scanf("%ld %ld %ld", &x, &y, &z)
#define scLI4(w,x,y,z) scanf("%ld %ld %ld %ld", &w, &x, &y, &z)

#define scLLI(x) scanf("%I64d", &x)
#define scLLI2(x,y) scanf("%I64d %I64d", &x, &y)
#define scLLI3(x,y,z) scanf("%I64d %I64d %I64d", &x, &y, &z)
#define scLLI4(w,x,y,z) scanf("%I64d %I64d %I64d %I64d", &w, &x, &y, &z)

#define scd(x) scanf("%lf", &x)
#define scd2(x) scanf("%lf %lf", &x, &y)
#define scd3(x) scanf("%lf %lf %lf", &x, &y, &z)

#define loop(x,y,z) for(int x=y; x<z; x++)
#define cloop(x,y,z,in) for(int x=y; x<z; x+=in)

#define vi vector<int>
#define vs vector<string>
#define pb(x) push_back(x)
#define sz size()
#define clr clear()
#define vsort(x) sort(x.begin(),x.end())
#define rev(x) reverse(x.begin(),x.end())

#define pii pair<int,int>
#define uu first
#define vv second

#define si stack<int>
#define sLI stack<LI>
#define sLLI stack<LLI>
#define qi queue<int>
#define qLI queue<LI>
#define qLLI queue<LLI>

#define mx 1009
#define inf 2147483647
#define eps 0.00001

bool flag[mx];
vector<int> prime;
vector<int> cr;
vector<int> tr;
map<long,int> mp;

void makePrime() {
for(long i=2; i<=mx; i++) {
if(!flag[i]) {
prime.pb(i);
for(long j= 2*i; j<=mx; j+=i) {
flag[j]= true;
}
}
}

return;
}

void getPrimeFactors(int n) {
int sq= sqrt(n);
int prlen= prime.sz;

for(int i=0; i<prlen && prime[i]<=sq; i++) {
if(n%prime[i]==0) {
cr.pb(prime[i]);
while(n%prime[i]==0) {
n/=prime[i];
++mp[prime[i]];
}
sq= sqrt(n);
}
}

if(n>1) {
cr.pb(n);
++mp[n];
}
}

int power(int n, int p){
if(!p) return 1;

int ed= n;
loop(i,1,p)
ed*= n;
return ed;
}


int getZeros(int n) {

int pr= cr[cr.sz-1];
out2("Prime is: ",pr) el;


//getPrimeFactors(n);
int cnt= 0, exp= 1;

while(true){
//cout << "I'm in a mess" << endl;

int x= power(pr,exp);
if(x>n){
cout << "Broken" << endl;
break;
}
cnt+= n/x;
out2("--> ", n/x) el;
++exp;
}

cout << "Found it's happy ending" << endl;

return cnt;
}

int main() {
makePrime();
int t;
sci(t);

int n, b;
loop(i,0,t){
sci2(n,b);
printf("Case %d: ", i+1);

getPrimeFactors(b);

cout << getZeros(n) << endl;

}
return 0;
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.