T B 题面:
idea:这题一开始就知道是类似lqb里面的日期问题,但是当年准备lqb的时候并没有学习日期公式(就是蔡勒公式),只能写了一个没那么暴力的暴力程序。思路是先用十亿减去现在拥有的的钱数,然后一个月一个月地递推过去。
ACcode:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<map>
#define LL long long
#define INF 0x3f3f3f3f
#define N 20000000
using namespace std;
LL sum,money,t,n,year,month,day,l,r,tot;
LL mon[20];
LL getdays()
{
LL l = 1,r = 160000;
while( l<r )
{
LL mid = (l+r)/2;
LL h = (mid*mid + mid)/2;
if( h>=tot )
{
r = mid;
}
else l = mid+1;
}
return l;
}
bool judge( LL x )
{
if( (x%4==0&&x%100!=0) || x%400==0 ) return true;
else return false;
}
void getday(LL x,LL y,LL z,LL h)
{
LL sheng,ydays;
while(1)
{
if( y!=2 ) ydays = mon[y];
else
{
if( judge(x)==true ) ydays = 29;
else ydays = 28;
}
sheng = ydays - z;
if( sheng >= h )
{
year = x;
month = y;
day = z;
sum = h;
return ;
}
h -= sheng;
z = 0;
y++;
if( y>12 )
{
x++;
y = 1;
}
}
}
void work()
{
tot = 1000000000 - money;
sum = getdays();
getday(year,month,day,sum);
printf("%lld %lld %lld\n",year,month,day+sum);
}
int main()
{
mon[1] = 31;
mon[2] = 28;
mon[3] = 31;
mon[4] = 30;
mon[5] = 31;
mon[6] = 30;
mon[7] = mon[8] = 31;
mon[9] = 30;
mon[10] = 31;
mon[11] = 30;
mon[12] = 31;
cin>>t;
while( t-- )
{
scanf("%lld %lld %lld %lld",&money,&year,&month,&day);
work();
}
return 0;
}
T H 题面:
idea:就是哥德巴赫猜想,给出一个小于1e9的数字,让你拆开成两个质数的和。(其实一亿内的质数挺少的)我们只需要晒出1到10000的质数,然后对每个n,减去筛出的质数后再判断是否是质数就好.O(√n log2 n)
ACcode:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<map>
#define LL long long
#define INF 0x3f3f3f3f
#define N 20000000
using namespace std;
LL pr[N],tot = 0;
int pd[N];
int sum = 0;
void get_prime()
{
for(LL i=2;i<=100000;i++)
{
if( pd[i]!=1 )
{
tot++;
pr[tot] = i;
}
for(int j=1;j<=tot;j++)
{
if( i*pr[j]>100000 ) break;
pd[ i*pr[j] ] = 1;
if( i%pr[j]==0 ) break;
}
}
}
LL n;
bool judge(LL x)
{
LL y = sqrt(x);
for(LL i=2;i<=y;i++)
{
if( x%i==0 ) return false;
}
return true;
}
int main()
{
get_prime();
cin>>n;
for(int j=1;j<=tot;j++)
{
LL t = n-pr[j];
if( judge( t )==true )
{
cout<<pr[j]<<" "<<t;
return 0;
}
}
return 0;
}
|