Untitled
unknown
c_cpp
a year ago
916 B
4
Indexable
Never
#include<stdio.h> int prime(int n) // ham kiem tra so nguyen to { return (n == 2 || n == 3 || n == 5 || n == 7 ||n == 11 ||n == 13 ||n == 17); } int leapYear(int n) // ham kiem tra nam nhuan { return ((n%4==0) &&(n % 100 != 0) || (n % 400 == 0)); } int main() { int p,q,a,b,x,y; scanf("%d%d%d%d",&p,&q,&a,&b); // nhap if(a % b == 0) { x = 0; y = 0; } else { double t = (double)a/ (double)b; // phep chia lay so thuc cua a va b int k = (int)(t*10) % 10 + (int)(t*100) % 10; // tong phan tram va phan 10 if(prime(k)) a *= 10; else a *= 100; k = a / b ; // phep chia lay so nguyen x = k / 10 % 10; // hang chuc y = k / 100 % 10; // hang tram } int year = p*1000 + q*100 + x*10 + y; // nam if(leapYear(year)) printf("YES "); else printf("NO "); printf("%d",year); }