Shirlies
宁静专注认真的程序媛~
摘要: 我是用笨方法做的,首先找出该值的范围,然后分奇数偶数讨论。#include "stdio.h"#include "math.h"int main(){int n;int temp;while(scanf("%d",&n)==1&&n){temp=(int)pow(n,0.5);if(temp*temp==n){if(temp%2==0)printf("%d 1\n",temp);elseprintf("1 %d\n",temp);continue;}if(temp%2== 阅读全文
posted @ 2012-01-18 21:20 Shirlies 阅读(166) 评论(0) 推荐(0) 编辑
摘要: 用double就可以了Double(双精度浮点型)变量存储为 IEEE 64 位(8 个字节)浮点数值的形式,它的范围在负数的时候是从 -1.79769313486232E308 到 -4.94065645841247E-324,而正数的时候是从 4.94065645841247E-324 到 1.79769313486232E308(来自百度)#include "stdio.h"#include "math.h"int main(){double n,p;double temp;while(scanf("%lf%lf",&n 阅读全文
posted @ 2012-01-18 20:41 Shirlies 阅读(245) 评论(0) 推荐(0) 编辑
摘要: 欧拉函数φ(x)=x(1-1/p1)(1-1/p2)(1-1/p3)(1-1/p4)…..(1-1/pn),其中p1, p2……pn为x的所有质因数,x是不为0的整数。φ(1)=1(唯一和1互质的数就是1本身)。 (注意:每种质因数只一个。比如12=2*2*3欧拉公式那么φ(12)=12*(1-1/2)*(1-1/3)=4)#include "stdio.h"int prime[10000]={1,2,3};int main(){int t;int n;int count;int i,k=3,j,ok;for(i=4;i<32768;i++){ok=1;for(j=1 阅读全文
posted @ 2012-01-18 17:26 Shirlies 阅读(166) 评论(0) 推荐(0) 编辑
摘要: a/gcd(a,b)与b/gcd(a,b)互素就可以做出来了……#include "stdio.h"int gcd(int a,int b){if(a%b==0)return b;elsereturn gcd(b,a%b);}int main(){int a,b;int t,temp;int i;scanf("%d",&t);while(t--){scanf("%d%d",&a,&b);temp=a/b;for(i=2;i<1000000;i++){if(gcd(i,temp)==1){break;}}p 阅读全文
posted @ 2012-01-18 16:22 Shirlies 阅读(230) 评论(0) 推荐(0) 编辑
摘要: 思路是:通分后求分子的最小公倍数,在除以通分后的分母(看了别人的思路才知道分数的最小公倍数是这样求的,起初只是知道要求公倍数,但是不知道怎么求,汗,我可怜的数学啊~~~)#include "stdio.h"__int64 gcd(__int64 a,__int64 b){if(a%b==0)return b;elsereturn gcd(b,a%b);}int main(){int T;__int64 t1,q1,t2,q2,ts,kq,t;scanf("%d",&T);while(T--){scanf("%I64d/%I64d %I6 阅读全文
posted @ 2012-01-18 10:07 Shirlies 阅读(370) 评论(0) 推荐(0) 编辑