1.小明刚刚找到工作,老板人很好,只是老板夫人很爱购物。老板忙的时候经常让小明帮忙到商场代为购物。小明很厌烦,但又不好推辞。这不,XX大促销又来了!老板夫人开出了长长的购物单,都是有打折优惠的。小明也有个怪癖,不到万不得已,从不刷卡,直接现金搞定。现在小明很心烦,请你帮他计算一下,需要从取款机上取多少现金,才能搞定这次购物。取款机只能提供100元面额的纸币。小明想尽可能少取些现金,够用就行了。你的任务是计算出,小明最少需要取多少现金。以下是让人头疼的购物单,为了保护隐私,物品名称被隐藏了。
#include
<algorithm>
#include
<string.h>
#include
<iostream>
#include
<stdio.h>
#include
<string>
#include
<vector>
#include
<queue>
#include
<map>
#include
<set>
using
namespace
std;
int
main(){
freopen(".data","r",stin);
double
ans = 0,a,b;
char
buf[1110];
while(scanf("%s%lf%lf",buf,&a,&b)!=EOF)
{
ans
+= a*b/100;
}
printf("%lf\n",ans);
return
0;
}
//ans:5200
2.
标题:等差素数列
2,3,5,7,11,13,....是素数序列。
类似:7,37,67,97,127,157 这样完全由素数组成的等差数列,叫等差素数数列。
上边的数列公差为30,长度为6。
2004年,格林与华人陶哲轩合作证明了:存在任意长度的素数等差数列。
这是数论领域一项惊人的成果!
有这一理论为基础,请你借助手中的计算机,满怀信心地搜索:
长度为10的等差素数列,其公差最小值是多少?
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
const long long N = 1000010;
int dp[N]={1,1,0};
int prim[N],tot = 0;
void init()
{
for(long long i = 2 ; i < N ; i ++)
{
if(dp[i])continue;
prim[tot++]=i;
for(long long j = i ; j * i < N ; j ++){
dp[i*j] = 1;
}
}
}
int main()
{
init();
printf("%d\n",tot);
for(int i = 1 ; i*10 < N ; i ++){
for(int j = 0 ; j < tot ; j ++){
int flag = 1,temp = prim[j];
for(int k = 1 ; k < 10 ; k ++)
{
if(temp + i >= N || dp[temp + i] == 1){
flag = 0;break;
}else{
temp = temp + i;
}
}
if(flag == 1){
printf("%d %d\n",i,prim[j]);
return 0;
}
}
}
return 0;
}
//ans:210