int main() { int i; for(i = 2; i * i < maxn; i++) { if(num[i] == 1) continue; for(int j = i; i * j < maxn; j++) if(num[i*j] != 1) num[i*j] = 1; else continue; } for(i = 1; i < maxn; i++) if(num[i] == 0 && num[extra(i)] <= 0) num[i] = -1; int nt = 0; for(i = 1; i < maxn; i++) num[i] = (num[i] == -1) ? ++nt : nt; int T; scanf("%d", &T); for(i = 1; i <= T; i++) { int l, r; scanf("%d%d", &l, &r); int tot = num[r] - num[l]; if(jd(l) && jd(extra(l))) tot++; printf("Case #%d: %d\n", i, tot); } return 0; }
int ExtDate::dayOfWeek() const { //JD 2451545 (01 Jan 2000) was a Saturday, which is dayOfWeek=6. int a_day = (( jd() - 2451545 + 6 ) % 7); if ( a_day < 0 ) a_day += 7; return (a_day == 0) ? 7 : a_day; }
int ExtDate::weekNumber( int *yearNum ) const { // the year and week number are those of the next Sunday. ExtDate a_date( jd() - dayOfWeek() + 7); *yearNum = a_date.year(); return 1 + int( a_date.dayOfYear()/7 ); }
const t_julianDay jd0UT(t_aTime aTime) { aTime.second = 0; aTime.minute = 0; aTime.hour = 0; return jd(0 == aTime.utcOffset ? aTime : makeUT(aTime)); }
QByteArray serializeJson(QVariantMap json) { #ifdef QT5 QJsonDocument jd(QJsonObject::fromVariantMap(json)); return jd.toJson(); #else QJson::Serializer serializer; QByteArray data = serializer.serialize(json); return data; #endif }
double SinH(int year, int month, int day, double UT){ double TU0, TU, TU2, TU3, LambdaMoon, BetaMoon, R, AGE, frac(), jd(); double RA_Sun, DEC_Sun, T0, gmst, lmst, Tau, epsilon; double M, DL, L, SL, X, Y, Z, RHO; TU0 = (jd(year, month, day, 0.0) - 2451545.0)/36525.0; TU = (jd(year, month, day, UT+62.0/3600.0) - 2451545.0)/36525.0; TU2 = TU*TU; TU3 = TU2*TU; M = P2*frac(0.993133 + 99.997361*TU); DL = 6893.0*sin(M) + 72.0*sin(2.0*M); L = P2*frac(0.7859453 + M/P2 + (6191.2*TU+DL)/1296e3); SL = sin(L); X = cos(L); Y = cosEPS*SL; Z = sinEPS*SL; RHO = sqrt(1.0-Z*Z); DEC_Sun = atan2(Z, RHO); RA_Sun = (48.0/P2)*atan(Y/(X+RHO)); if (RA_Sun < 0) RA_Sun += 24.0; RA_Sun = RA_Sun*15.0*RadPerDeg; /* * Compute Greenwich Mean Sidereal Time (gmst) */ UT = 24.0*frac( UT/24.0 ); /* gmst = 6.697374558 + 1.0027379093*UT + (8640184.812866*TU0 +(0.093104-6.2e-6*TU)*TU2)/3600.0; */ gmst = 6.697374558 + 1.0*UT + (8640184.812866+(0.093104-6.2e-6*TU)*TU)*TU/3600.0; lmst = 24.0*frac( (gmst-Glon/15.0) / 24.0 ); Tau = 15.0*lmst*RadPerDeg - RA_Sun; return( SinGlat*sin(DEC_Sun) + CosGlat*cos(DEC_Sun)*cos(Tau) ); }
const t_hord Stars::horizontalPosition( const t_aTime &aTime , const t_longf latitude , const t_longf longitude , const t_longf a2000 , const t_longf d2000 , const t_longf mpa2000 , const t_longf mpd2000) { t_julianDay t(jd(aTime)); t_julianDay s(siderealTime(aTime)); t_equd equ = apparentPosition(t, a2000, d2000, mpa2000, mpd2000); return equ.toHorizontal(s, latitude, longitude); }
bool PublicDay::PublicDayCalculate(PublicDayObject& obj) { double m0 = 0; double mn = 0; double tmpYear = julianDay_.GetYear(); double tmpMonth = julianDay_.GetMonth(); // 日历物件初始化 JulianDay jd(tmpYear, tmpMonth, 1, 12.0, 0.0, 0.0); m0 = floor(jd.GregorianDayToJulianDay()) - commonDef::J2000; // 公历某年的月首,中午 if(moonCalculate_.ZQ.lunarInfoList_.empty() || m0 < moonCalculate_.ZQ.lunarInfoList_[0] || m0 >= moonCalculate_.ZQ.lunarInfoList_[24]) moonCalculate_.calcY(m0); double nextMonth = tmpMonth + 1; if (nextMonth > 12) { tmpYear++; tmpMonth = 1; } // C#: 如果月份大于 12, 则年数 + 1, 月数取 1 JulianDay jdNext(tmpYear, nextMonth, 1, 12.0, 0.0, 0.0); mn = jdNext.GregorianDayToJulianDay() - commonDef::J2000 - m0; // 本月天数(公历) double w0 = fmod((m0 + commonDef::J2000 + 1), 7); //本月第一天的星期 obj.d0 = julianDay_.GregorianDayToJulianDay() - commonDef::J2000; // 儒略日,北京时12:00 obj.di = julianDay_.GetDay(); // 公历月内日序数 obj.y = (int)julianDay_.GetYear(); // 公历年 obj.m = (int)julianDay_.GetMonth(); // 公历月 obj.dn = mn; // 公历月天数 obj.week0 = w0; // 月首的星期 obj.week = fmod((w0 + obj.di), 7); // 当前日的星期 obj.weeki = floor((w0 + obj.di) / 7); // 本日所在的周序号 obj.weekN = floor((w0 + mn - 1) / 7) + 1; // 本月的总周数 obj.d = (int)julianDay_.GetDay(); //公历日名称 double mk = (int)floor((obj.d0 - moonCalculate_.ZQ.lunarInfoList_[0] - 15) / 30.43685); if (mk < 11 && obj.d0 >= moonCalculate_.ZQ.lunarInfoList_[2 * (unsigned int)mk + 2]) mk++; //星座所在月的序数,(如果j=13,ob.d0不会超过第14号中气) obj.XiZ = commonDef::Constellation_Tab[(int)fmod((mk + 12), 12)]; return true; }
void Updates::readStdout() { QByteArray rgb = pprocess->readLine(); if (rgb.isEmpty()) return; if (QChar(rgb[0]).isDigit()) { int percent = QString(rgb).toInt(); if (percent >= 0 || percent <= 100) ui->progressBar->setValue(percent); } else if (rgb[0] == '{') { ui->progressBar->setValue(0); // back to 0 to prepare for "Update Now" QJsonDocument jd(QJsonDocument::fromJson(rgb)); const QJsonObject &json = jd.object(); ui->textCurrent->setText(json["currentVersion"].toString()); ui->textAvailable->setText(json["futureVersion"].toString()); ui->textStatus->setText(""); } }
double SinH(int year, int month, int day, double UT) { double TU, frac(), jd(); double RA_Moon, DEC_Moon, gmst, lmst, Tau, Moon(); double angle2pi(); TU = (jd(year, month, day, UT) - 2451545.0)/36525.0; /* this is more accurate, but wasteful for this -- use low res approx. TU2 = TU*TU; TU3 = TU2*TU; Moon(TU, &LambdaMoon, &BetaMoon, &R, &AGE); LambdaMoon *= RadPerDeg; BetaMoon *= RadPerDeg; epsilon = (23.43929167 - 0.013004166*TU - 1.6666667e-7*TU2 - 5.0277777778e-7*TU3)*RadPerDeg; RA_Moon = angle2pi(atan2(sin(LambdaMoon)*cos(epsilon)-tan(BetaMoon)*sin(epsilon), cos(LambdaMoon))); DEC_Moon = asin( sin(BetaMoon)*cos(epsilon) + cos(BetaMoon)*sin(epsilon)*sin(LambdaMoon)); */ MiniMoon(TU, &RA_Moon, &DEC_Moon); RA_Moon *= 15.0*RadPerDeg; DEC_Moon *= RadPerDeg; /* * Compute Greenwich Mean Sidereal Time (gmst) */ UT = 24.0*frac( UT/24.0 ); /* this is for the ephemeris meridian??? gmst = 6.697374558 + 1.0027379093*UT + (8640184.812866+(0.093104-6.2e-6*TU)*TU)*TU/3600.0; */ gmst = UT + 6.697374558 + (8640184.812866+(0.093104-6.2e-6*TU)*TU)*TU/3600.0; lmst = 24.0*frac( (gmst-Glon/15.0) / 24.0 ); Tau = 15.0*lmst*RadPerDeg - RA_Moon; return( SinGlat*sin(DEC_Moon) + CosGlat*cos(DEC_Moon)*cos(Tau) ); }
int main() { int i; num[1] = 1; for(i = 2; i * i < maxn; i++) { if(num[i] == 1) continue; for(int j = i; i * j < maxn; j++) if(num[i*j] != 1) num[i*j] = 1; else continue; } int next = 0; memcpy(nn, num, sizeof(num)); for(i = 1; i < maxn; i++) { if(num[i] == 0) jd(i, next); else num[i] = next; } int T; scanf("%d", &T); for(i = 1; i <= T; i++) { int l, r, tot = 0; scanf("%d%d", &l, &r); if(nn[l] == -1) tot = num[r] - num[l] + 1; else tot = num[r] - num[l]; printf("Case #%d: %d\n", i, tot); } return 0; }
int ExtDate::daysTo( const ExtDate & a_date) const { return a_date.jd() - jd(); }
ExtDate ExtDate::addDays( int days ) const { ExtDate a_date; a_date.setJD( jd() + days ); return a_date; }
double seti_time::julian() const { return(jd().uval()); }
int ExtDate::dayOfYear() const { return jd() - GregorianToJD( year(), 1, 1) + 1; }
/* * main */ int main(int argc, char *argv[]) { struct tm *gTime, *gmt; struct stat fi; XEvent event; Pixmap NewPixmap, NewShapeMask; XpmAttributes Attributes; Colormap cmap; int n, s, m, dt1, dt2, dt3, len; int Year, Month, Day; int Hours, Mins, Secs; int i, j, Width, Height, yoff, fd, Flag; long CurrentLocalTime; double UT, hour24(), jd(), CurrentJD, OldFileUT, FileUT; char command[1040], ImageName[256]; int havePixmap= 0; /* * Parse any command line arguments. */ ParseCMDLine(argc, argv); /* * Figure out what the name of the image xpm file should be... */ len = strlen(ImageURL); for (j = 0, i=0; i<len; ++i){ if (ImageURL[i] == '/') j = i; } strcpy(ImageName, ImageURL+j+1); sprintf(XpmFileName, "%s/.wmGrabImage/%s.xpm", getenv("HOME"), ImageName); sprintf(ImageFileName, "%s/.wmGrabImage/%s", getenv("HOME"), ImageName); openXwindow(argc, argv, wmGrabImage_master, wmGrabImage_mask_bits, wmGrabImage_mask_width, wmGrabImage_mask_height); cmap = DefaultColormap(display, DefaultScreen(display)); /* * Loop until we die */ n = 32000; s = 32000; m = 32000; dt1 = 32000; dt2 = 32000; dt3 = 32000; DblClkDelay = 32000; UpToDate = 0; FileUT = -999.0; Flag = 1; NewShapeMask = 0; Attributes.nalloc_pixels = 0; while(1) { /* * Keep track of # of seconds */ if (m > 100){ m = 0; ++dt1; ++dt2; ++dt3; } else { /* * Increment counter */ ++m; } /* * Double Click Delays * Keep track of click events. If Delay too long, set GotFirstClick's to False. */ if (DblClkDelay > 15) { DblClkDelay = 0; GotFirstClick1 = 0; GotDoubleClick1 = 0; GotFirstClick2 = 0; GotDoubleClick2 = 0; GotFirstClick3 = 0; GotDoubleClick3 = 0; } else { ++DblClkDelay; } /* * Process any pending X events. */ while(XPending(display)){ XNextEvent(display, &event); switch(event.type){ case Expose: RedrawWindow(); break; case ButtonPress: pressEvent(&event.xbutton); break; case ButtonRelease: break; } } /* * Draw window. */ if (ForceUpdate||Flag){ /* * Compute Current Julian Date */ CurrentLocalTime = time(CurrentTime); gTime = gmtime(&CurrentLocalTime); Year = gTime->tm_year+1900; Month = gTime->tm_mon+1; Day = gTime->tm_mday; Hours = gTime->tm_hour; Mins = gTime->tm_min; Secs = gTime->tm_sec; UT = (double)Hours + (double)Mins/60.0 + (double)Secs/3600.0; CurrentJD = jd(Year, Month, Day, UT); /* * Clear window. */ copyXPMArea(5, 69, 54, 54, 5, 5); if (havePixmap) { /* * free up the colors, if we alloc'd some before */ if (Attributes.nalloc_pixels > 0) XFreeColors(display, cmap, Attributes.alloc_pixels, Attributes.nalloc_pixels, 0); /* * Free last pixmap -- we dont need it anymore... * A ShapeMask is returned if the Pixmap had the color None used. * We could probably change Transparent to None to make use of this, but for now, * lets just ignore it... */ if ( NewShapeMask != 0 ) XFreePixmap(display, NewShapeMask); XFreePixmap(display, NewPixmap); XpmFreeAttributes(&Attributes); havePixmap= 0; } /* * Grab new pixmap. Accept a reasonable color match. */ Attributes.valuemask = XpmExactColors | XpmCloseness | XpmReturnAllocPixels; Attributes.exactColors = 0; Attributes.closeness = 40000; if (XpmReadFileToPixmap(display, Root, XpmFileName, &NewPixmap, &NewShapeMask, &Attributes) >= 0){ Height = Attributes.height; Width = Attributes.width; yoff = (CenterImage) ? (54 - Height)/2 : 0; XCopyArea(display, NewPixmap, wmgen.pixmap, NormalGC, 0, 0, Width, Height, 5, 5+yoff); Flag = 0; ForceUpdate = 0; havePixmap= 1; } /* * Make changes visible */ RedrawWindow(); } /* * Check xpm file status */ if (dt2 > 1){ dt2 = 0; if ( (fd = open(XpmFileName, O_RDONLY)) >= 0 ) { fstat(fd, &fi); close(fd); gmt = gmtime(&fi.st_mtime); OldFileUT = FileUT; FileUT = (double)gmt->tm_hour + (double)gmt->tm_min/60.0 + (double)gmt->tm_sec/3600.0; if (FileUT != OldFileUT) ForceUpdate = 1; } } /* * Check every 5 min if the values are not up to date... */ if (ForceUpdate2||(dt3 > UpdateDELAY)){ dt3 = 0; /* * Execute Perl script to grab the Latest METAR Report */ if (ConvertGeometry != NULL) sprintf(command, "GrabImage %s %s &", ImageURL, ConvertGeometry); else sprintf(command, "GrabImage %s &", ImageURL); system(command); ForceUpdate = 1; ForceUpdate2 = 0; } /* * Wait for next update */ usleep(DELAY); } }
days seti_time::jd(const days &j) { *this=seti_time(j,JD0); return jd(); }
const t_aTime makeUT(const t_aTime &aTime) { return makeTime(jd(aTime) - aTime.utcOffset / 3600.0 / 24.0, 0); }
bool Ephemeris::loadState(const ossimKeywordlist& kwl, const char* prefix) { static const char MODULE[] = "Ephemeris::loadState"; bool result = true; std::string pfx; if (prefix) { pfx = prefix; } pfx += "ephemeris."; const char* lookup = 0; ossimString s; double d; lookup = kwl.find(pfx.c_str(), DATE_JULIAN_KW); if (lookup) { s = lookup; d = s.toDouble(); JulianDate jd(d); _date.set_day0hTU(jd); } else { ossimNotify(ossimNotifyLevel_WARN) << MODULE << " Keyword not found: " << DATE_JULIAN_KW << "\n"; result = false; } lookup = kwl.find(pfx.c_str(), DATE_SECOND_KW); if (lookup) { s = lookup; d = s.toDouble(); _date.set_second(d); } else { ossimNotify(ossimNotifyLevel_WARN) << MODULE << " Keyword not found: " << DATE_SECOND_KW << "\n"; result = false; } lookup = kwl.find(pfx.c_str(), DATE_DECIMAL_KW); if (lookup) { s = lookup; d = s.toDouble(); _date.set_decimal(d); } else { ossimNotify(ossimNotifyLevel_WARN) << MODULE << " Keyword not found: " << DATE_DECIMAL_KW << "\n"; result = false; } lookup = kwl.find(pfx.c_str(), POSITION_KW); if (lookup) { std::string ps = lookup; ossimDpt3d pt; pt.toPoint(ps); _position[0] = pt.x; _position[1] = pt.y; _position[2] = pt.z; } else { ossimNotify(ossimNotifyLevel_WARN) << MODULE << " Keyword not found: " << POSITION_KW << "\n"; result = false; } lookup = kwl.find(pfx.c_str(), VELOCITY_KW); if (lookup) { std::string ps = lookup; ossimDpt3d pt; pt.toPoint(ps); _vitesse[0] = pt.x; _vitesse[1] = pt.y; _vitesse[2] = pt.z; } else { ossimNotify(ossimNotifyLevel_WARN) << MODULE << " Keyword not found: " << VELOCITY_KW << "\n"; result = false; } return result; }
const t_julianDay jdUT(const t_aTime &aTime) { return jd(0 == aTime.utcOffset ? aTime : makeUT(aTime)); }
int main () { int err = 0; try { namespace sja = saga::job::attributes; namespace sa = saga::attributes; // create a job description template saga::job::description templ; templ.set_attribute (sja::description_executable, SAGA_TEST_BIN_BC); std::vector <std::string> args; args.push_back ("-ql"); templ.set_vector_attribute (sja::description_arguments, args); templ.set_attribute (sja::description_interactive, sa::common_true); // create_job valid interactive job { saga::job::service js (saga::get_default_session ()); saga::job::description jd (templ); saga::job::job j = js.create_job (jd); j.run (); saga::job::ostream io_in = j.get_stdin (); saga::job::istream io_out = j.get_stdout (); saga::job::istream io_err = j.get_stderr (); std::string q ("6*7"); io_in << q << std::endl; char a[1024]; io_out.getline (a, sizeof (a)); std::cout << "question: " << q << std::endl; std::cout << "answer : " << a << std::endl; if ( std::string (a) != "42" ) { std::cerr << "unexpected answer: -" << a << "- != -42-" << std::endl; err++; } io_in << "quit\n" << std::endl; j.wait (); } // create_job *in*valid interactive job { saga::job::service js (saga::get_default_session ()); saga::job::description jd (templ); jd.set_attribute (sja::description_executable, "/does/not/exist"); // expecting a BadParameter exception try { saga::job::job j = js.create_job (jd); } catch ( const saga::bad_parameter & e ) { // all is well } catch ( const saga::exception & e ) { std::cerr << "incorrect exception (! BadParameter): " << e.what () << std::endl; std::cout << "error: " << e.get_error () << std::endl; std::cout << " : " << saga::BadParameter << std::endl; err++; } } // create_job w/o executable? BadParameter expected { saga::job::service js (saga::get_default_session ()); saga::job::description jd; // expecting a BadParameter exception try { saga::job::job j = js.create_job (jd); } catch ( const saga::bad_parameter & e ) { // all is well } catch ( const saga::exception & e ) { std::cerr << "incorrect exception (! BadParameter): " << e.what () << std::endl; std::cout << "error: " << e.get_error () << std::endl; std::cout << " : " << saga::BadParameter << std::endl; err++; } } } catch ( const saga::not_implemented & e ) { // this can always happen std::cout << "WARNING: expected none, got NotImplemented exception" << std::endl; } catch ( const saga::exception & e ) { std::cerr << "Exception: " << e.what () << std::endl; err++; } return err; }
// Modified Julian Date. const t_julianDay mjd(t_aTime aTime) { return jd(aTime) - 2400000.5; }
bool ExtDate::isValid() const { return ( jd() != INVALID_DAY && isValid( year(), month(), day() ) ); }