#include <iostream>
using namespace std;
int main(void){
long long n, m;
cin>>n>>m;
long long ans5 = 0;
long long ans2 = 0;
// 5의 개수
for(long long i = 5; i <= n; i *= 5) ans5 += n / i; // n!
for(long long i = 5; i <= n - m; i *= 5) ans5 -= (n - m) / i; // (n - m)!
for(long long i = 5; i <= m; i *= 5) ans5 -= m / i; // m!
// 2의 개수
for(long long i = 2; i <= n; i *= 2) ans2 += n / i; // n!
for(long long i = 2; i <= n - m; i *= 2) ans2 -= (n - m) / i; // (n - m)!
for(long long i = 2; i <= m; i *= 2) ans2 -= m / i; // m!
cout<<(ans5 > ans2 ? ans2 : ans5);
}
#include <iostream>
using namespace std;
int main(void){
int n;
cin>>n;
for(int i = 2; i * i <= n ; i++){
while(n % i == 0){
cout<<i<<'\n';
n /= i;
}
}
if(n>1) cout<<n<<'\n';
}
#include <iostream>
#include <math.h>
using namespace std;
const int MAX = 1000001;
int prime[MAX]; // 0: 소수,1: 소수x
// 에라토스테네스의 채
void eratostenes(void){
for(int i = 2; i * i < MAX; i++) {
if(!prime[i]) // i가 소수일 경우
for(int j = i * i; j < MAX; j += i) // i의 배수는 모두 소수가 아님
prime[j] = 1;
}
prime[1] = 1;
}
int main(void){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
eratostenes();
while(1){
cin>>n;
if(n == 0) break;
for(int i = 3; i <= n / 2; i++) {
if(prime[i] == 0 && prime[n - i] == 0){
cout<<n<<" = "<<i<<" + "<<n - i<<'\n';
break;
} else if(i == n / 2)
cout<<"Goldbach's conjecture is wrong.\n";
}
}
}
c++ cn
#include <iostream>
#include <math.h>
using namespace std;
bool cn(int n){
int m = sqrt(double(n));
if(n == 1) return false;
for(int i = 2; i <= m; i++) {
if(n % i == 0) return false;
}
return true;
}
int main(void){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
while(1){
cin>>n;
if(n == 0) break;
for(int i = 3; i <= n / 2; i++) {
if(cn(n - i) && cn(i)){
cout<<n<<" = "<<i<<" + "<<n - i<<'\n';
break;
}
else if(i == n / 2) cout<<"Goldbach's conjecture is wrong.\n";
}
}
}
python 에라토스테네스
def eratos(n):
p=2
while p*p<=n:
if prime[p]==True:
for j in range(p*p, n+1, p):
prime[j]=False
p=p+1
if __name__ == "__main__":
prime=[True for _ in range(1000001)]
eratos(1000000)
while True:
n=int(input())
if n==0:
break
else:
for i in range(2, n):
if prime[i]==True and prime[n-i]==True:
print("%d = %d + %d"%(n, i, n-i))
break
else:
print("Goldbach's conjecture is wrong.")
#include <iostream>
#include <math.h>
using namespace std;
bool cn(int n){
int m = sqrt(double(n));
if(n == 1) return false;
for(int i = 2; i <= m; i++) {
if(n % i == 0) return false;
}
return true;
}
int main(void){
int m, n; // m 이상, n 이하
cin>>m>>n;
for(int i = m; i <= n; i++)
if(cn(i)) cout<<i<<'\n';
}