周末训练笔记+UVA138+HDU2973【筛素数】【威尔逊定理】
来源:互联网 发布:java hello world 代码 编辑:程序博客网 时间:2024/05/27 20:58
这两天实在天冷了,比较适合宅起来敲俩代码,这俩个题目脑洞都比较大,之前没接触这个,先放上这俩,其余题目单发。
Street Numbers
:有个程序员每天都遛狗,这很程序员,他家住的街道上是一条直线,一次往左依次往右,发现两次遛狗门牌号的和是一样的,问他家的门牌思路:假设门牌是1-n,他家的是m,anemia根据等差数里求和公式,得出
直接暴力一发,tle,修改了输入处处还是超时,直接复制粘贴超时输出的答案,反正就这么10组
YAPTCHA
:在初等数论中,威尔逊定理给出了判定一个自然数是否为素数的充分必要条件。即:当且仅当p为素数时:( p -1 )! ≡ -1 ( mod p ),但是由于阶乘是呈爆炸增长的,其结论对于实际操作意义不大。
题意:计算题目里的式子
思路:假设x=3k+7,原式子=((x-1)!+1)/x+(x-1)!/x
根据威尔逊定理则有(p-1)!+1==0 mod(p) 所以x为合数时为0,当x为素数时加1即可
where [x] denotes the largest integer not greater than x.
Street Numbers
A computer programmer lives in a street with houses numbered consecutively (from 1) down one side of the street. Every evening she walks her dog by leaving her house and randomly turning left or right and walking to the end of the street and back. One night she adds up the street numbers of the houses she passes (excluding her own). The next time she walks the other way she repeats this and finds, to her astonishment, that the two sums are the same. Although this is determined in part by her house number and in part by the number of houses in the street, she nevertheless feels that this is a desirable property for her house to have and decides that all her subsequent houses should exhibit it.
Write a program to find pairs of numbers that satisfy this condition. To start your list the first two pairs are: (house number, last number):
Write a program to find pairs of numbers that satisfy this condition. To start your list the first two pairs are: (house number, last number):
6 8 35 49
There is no input for this program.
Output will consist of 10 lines each containing a pair of numbers, in increasing order with the last number, each printed right justified in a field of width 10 (as shown above).
6 8 35 49
#include<iostream>#include<stdio.h>#include<string.h>#include<cmath>using namespace std;#define ll long long#define N 1000000000int main(){ int num=0; int n,k; /*for(ll i=6;i<N;i++) { double temp=sqrt(0.5*(i*i+i)); int temp2=(int )temp; if(temp==temp2&&num<10) { printf("%10d%10d\n",temp2,i); num++; } }*/ cout<<" 6 8"<<endl; cout<<" 35 49"<<endl; cout<<" 204 288"<<endl; cout<<" 1189 1681"<<endl; cout<<" 6930 9800"<<endl; cout<<" 40391 57121"<<endl; cout<<" 235416 332928"<<endl; cout<<" 1372105 1940449"<<endl; cout<<" 7997214 11309768"<<endl; cout<<" 46611179 65918161"<<endl; return 0;}YAPTCHA
The math department has been having problems lately. Due to immense amount of unsolicited automated programs which were crawling across their pages, they decided to put Yet-Another-Public-Turing-Test-to-Tell-Computers-and-Humans-Apart on their webpages. In short, to get access to their scientific papers, one have to prove yourself eligible and worthy, i.e. solve a mathematic riddle.
However, the test turned out difficult for some math PhD students and even for some professors. Therefore, the math department wants to write a helper program which solves this task (it is not irrational, as they are going to make money on selling the program).
The task that is presented to anyone visiting the start page of the math department is as follows: given a natural n, compute
where [x] denotes the largest integer not greater than x.
However, the test turned out difficult for some math PhD students and even for some professors. Therefore, the math department wants to write a helper program which solves this task (it is not irrational, as they are going to make money on selling the program).
The task that is presented to anyone visiting the start page of the math department is as follows: given a natural n, compute
where [x] denotes the largest integer not greater than x.
1312345678910100100010000
0112222334282071609
#include<iostream>#include<stdio.h>#include<string.h>#include<cmath>using namespace std;#define ll long long#define N 5000010int vis[N];int prime[N];void Oula(int n){ int k=1; for(int i=2;i<n;i++) { if(!vis[i]) prime[k++]=i; for(int j=1;j<k&&i*prime[j]<n;j++) { vis[i*prime[j]]=1; if(i%prime[j]==0) break; } }}ll ans[1000010];int main(){ Oula(N); ans[0]=ans[1]=0; int temp=0; for(int i=2;i<1000010;i++) { if(vis[3*i+7]==0) temp=1; else temp=0; ans[i]=ans[i-1]+temp; } int n; int t; cin>>t; while(t--) { cin>>n; cout<<ans[n]<<endl; } return 0;}
阅读全文
0 0
- 周末训练笔记+UVA138+HDU2973【筛素数】【威尔逊定理】
- hdu2973威尔逊定理
- HDU2973(威尔逊定理)
- hdu2973 YAPTCHA(威尔逊定理)
- hdu2973 YAPTCHA(威尔逊定理)
- 周末训练笔记
- 周末训练笔记+POJ 1811 Prime Test【大素数判定】【素因子分解】
- 周末训练笔记(二)
- 周末训练笔记(三)
- 周末训练笔记(四)
- 周末训练笔记(10.1)
- 周末训练笔记+hdu1255+4288
- 周中训练笔记+筛素数
- 周末训练笔记+hdu1576 A/B
- 周末训练笔记+UVA11388+POJ2407+无名题
- 周末训练笔记+Uva10912+10994+POJ1006
- 周末训练笔记+数论主要知识点
- 周末训练笔记+HDU1205+POJ1306【排列组合】
- spring-cloud中config配置中心使用(基于eureka的高可用)
- node express route demo
- signalr
- fail-fast 与 fail-safe 机制有什么区别
- Java SecurityManager相关概念理解
- 周末训练笔记+UVA138+HDU2973【筛素数】【威尔逊定理】
- SpringBoot事务管理
- Java虚拟机的基本结构
- hdoj 1004 Let the Balloon Rise(map)
- 用BASS库重采样音频
- [leetcode]解决Move Zeroes的一点小心得
- Ubuntu下挂载硬盘剩余空间
- 交互式python shell
- 编写一个程序,可以一直接收键盘字符,如果是小写字符就输出对应的大写字符,如果接收的是大写字符,就输出对应的小写字符,如果是数字不输出