题解

45 条题解

  • 2
    @ 2017-08-25 01:52:12

    so water,我时间效率高

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    int main()
    {
        long long a,b,c,d,e,f,g,n,i,j;
        scanf("%lld",&n);
        for(i=3;i<=n;i=i+2)
        {
            a=i;
            if(n%2==0)
            {
                a=2;
                break;
            }
            if(n%3==0)
            {
                a=3;
                break;
            }
            if(n%a==0)
            break;
        }
        printf("%lld",n/a);
        return 0;
    }
    
  • 0
    @ 2016-11-27 19:57:11
    评测结果
    编译成功
    
    测试数据 #0: Accepted, time = 0 ms, mem = 512 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 508 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 508 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 512 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 512 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 508 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 508 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 508 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 504 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 504 KiB, score = 10
    Accepted, time = 0 ms, mem = 512 KiB, score = 100
    代码
    #include <cstdio>
    int main() {
        int n;
        scanf("%d",&n);
        for (int i = 2;i*i <= n;i++)
            if (!(n%i)) {
                printf("%d",n/i);
                return 0;
            }
    }
    
  • 0
    @ 2016-11-06 16:51:56

    #include<stdio.h>

    int main()
    {
    long long n,i;
    scanf("%lld",&n);
    for(i=2;i<=n/2;i++)
    if(n%i==0)
    {
    printf("%lld\n",n/i);
    return 0;
    }
    }

  • 0
    @ 2016-02-10 21:11:53

    第二个数据(也就是测试数据#1)是错的!!!!!!!!!!!!!

    #include <cmath>
    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    using namespace std;

    long long n,i,temp1,temp2,flag1;

    int main()
    {
    temp1=1;
    temp2=1;
    cin>>n;
    flag1=trunc(sqrt(n));

    for (i=2;i<=flag1;i++)
    {
    if (n%i==0)
    {
    temp1=i;
    break;
    }
    }

    for (i=2;i<=flag1;i++)
    {
    if (n%i==0)
    {
    temp2=i;
    //break;
    }
    }
    //我发现有break就可以AC,没有第二个数据就过不去 于是验证一下 第二个数据不合格

    if( (temp1<temp2)&&(temp2<n/temp2)&&(n/temp2 < n/temp1) )
    {cout<<n/temp1;}
    else{cout<<temp1+28;} //这句是为了让别的9个数据WA

    return 0;
    }

    编译成功

    测试数据 #0: WrongAnswer, time = 0 ms, mem = 556 KiB, score = 0
    测试数据 #1: Accepted, time = 0 ms, mem = 560 KiB, score = 10
    测试数据 #2: WrongAnswer, time = 0 ms, mem = 564 KiB, score = 0
    测试数据 #3: WrongAnswer, time = 0 ms, mem = 560 KiB, score = 0
    测试数据 #4: WrongAnswer, time = 0 ms, mem = 560 KiB, score = 0
    测试数据 #5: WrongAnswer, time = 0 ms, mem = 556 KiB, score = 0
    测试数据 #6: WrongAnswer, time = 0 ms, mem = 560 KiB, score = 0
    测试数据 #7: WrongAnswer, time = 0 ms, mem = 560 KiB, score = 0
    测试数据 #8: WrongAnswer, time = 0 ms, mem = 556 KiB, score = 0
    测试数据 #9: WrongAnswer, time = 0 ms, mem = 560 KiB, score = 0
    WrongAnswer, time = 0 ms, mem = 564 KiB, score = 10

    这就说明(temp1<temp2)&&(temp2<n/temp2)&&(n/temp2 < n/temp1) 为ture
    也就是说这个数据至少有 4个因数!!!!

    真特么坑比

  • 0
    @ 2015-12-14 04:52:10

    #include<stdio.h>
    int main()
    {
    unsigned long n,i;
    scanf("%lu",&n);
    for(i=2;i<=n/2;i++)
    if(n%i==0)
    {
    printf("%lu",n/i);
    return 0;
    }
    }
    晕,一开始想复杂了,没想到是简单题……&

  • 0
    @ 2015-12-13 15:34:06

    var
    i,j:longint;
    begin
    readln(j);
    for i:=(j div 2 ) downto 2 do
    if j mod i=0 then
    begin
    writeln(i);
    break
    end;
    end.

    • @ 2015-12-20 14:55:38

      include<stdio.h>

      int main()
      {
      unsigned long n,i;
      scanf("%lu",&n);
      for(i=2;i<=n/2;i++)
      if(n%i==0)
      {
      printf("%lu",n/i);
      return 0;
      }
      }

    • @ 2016-03-04 21:20:48

      666

  • 0
    @ 2015-10-31 10:33:31

    var
    i,m,s:longint;
    begin
    read(s);
    for i:=2 to s-1 do
    if s mod i =0 then m:=i;
    writeln(m);
    end.

  • 0
    @ 2015-10-24 16:26:38

    double

  • 0
    @ 2015-10-23 08:32:42

    Var n,i:longint;
    Begin
    readln(n);
    for i:=2 to n do
    if (n mod i)=0 then begin
    writeln(n div i); exit;end;
    end.

  • 0
    @ 2015-09-26 18:15:03

    #include <iostream>
    using namespace std;

    int main()
    {int n;cin>>n;
    for (int i=2;i*i<=n;i++)
    if (n%i==0){ cout<<n/i;break;}
    return 0;
    }

  • 0
    @ 2015-09-13 17:04:41

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    using namespace std;
    int pd(int x)
    {
    int i;
    for(i=2;i<=sqrt(x);i++){
    if(x%2==0){
    return 0;
    }
    }
    return 1;
    }
    int search(int x)
    {
    int i;
    for(i=2;i<=sqrt(x);i++){
    if(pd(i)&&pd(x/i)&&x%i==0){
    return x/i;
    }
    }
    }
    int main()
    {
    int n;
    scanf("%d",&n);
    printf("%d",search(n));
    return 0;
    }

  • 0
    @ 2015-08-17 09:12:13

    Mr.czh是大神,有什么问题找他

  • 0
    @ 2015-07-18 14:21:10

    #include<cstdio>
    #include<cmath>
    using namespace std;
    int tf(int x)
    {
    if(x<2)return 0;
    int t=(sqrt(double(x+1)));
    for(int i=2;i<=t;i++)
    if(x%i==0)return x/i;
    }
    int main()
    {
    int n,i,j,m;
    scanf("%d",&n);
    printf("%d\n",tf(n));
    return 0;
    }

    • @ 2015-07-18 14:21:32

      李玄j

  • 0
    @ 2015-02-23 12:47:54

    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 280 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 276 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 280 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 280 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 280 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 276 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 280 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 276 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 280 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 276 KiB, score = 10
    Accepted, time = 0 ms, mem = 280 KiB, score = 100
    代码
    #include <iostream>
    using namespace std;
    int main(){
    int n;
    cin>>n;
    for(int i=n-2; i>=2; i=i-2){
    if(n%i==0){
    cout<<i<<endl;
    break;
    }
    }
    }

  • 0
    @ 2015-02-10 10:58:58

    首先,我竟然傻傻的打表了,这叫求质数的线性筛法。
    #include<iostream>
    #include<string.h>
    #include<stdio.h>
    using namespace std;

    int prime[25000];
    int psize;
    void init(){
    bool a[50000];
    memset(a, -1, sizeof(a));
    int i, j;
    psize = 0;
    for (i = 2; i < 50000; i++){
    if (a[i]){
    prime[psize++] = i;

    }
    for (j = 0; j < psize&&prime[j]*i<50000; j++){
    a[prime[j] * i] = false;
    if (i%prime[j] == 0)break;
    }
    }
    }
    int main(){
    freopen("in.txt", "r", stdin);
    long long int n;
    cin >> n;
    init();
    int i;
    for (i = 0; i < psize; i++){
    if (n%prime[i] == 0){
    cout << n / prime[i] << endl;
    break;
    }
    }
    return 0;
    }

  • 0
    @ 2014-12-18 17:15:30

    让我作一个全面的题解:
    顺便让小白的我也总结下,虽然题目比较简单,但是还是要认真对待啊~

    首先,我们一看到题目,很容易想到枚举,:
    1:输入一个n,从2开始到N枚举,找到其(因数)然后用过程从2到N去mod,判断其是不是素数,就得到了思路最简单,但是却最笨的办法。

    2:优化,知道素数性质的不难明白,最大的素因数顶多是 N div 2 ,因此减少了一半的循环次数。

    3:虽然这样做已经很好了,但是如果你懂得一些数学知识,很容易找到一种超简便的办法(这就是下面为毛他们题解没有判断素数的过程)

    首先分解因数,只要因数有不是素数的,我们就会再对该因数分解,总之,无论如何,最后分解完一定是一堆素数的乘积。

    题目上说,这个数是素数A和素数B的乘积。
    那不就结了?已经是2个素数的乘积了,你还要分解么?
    所以这个数一定只有4个因数 1,A , B, 已经它自己
    所以从2开始枚举到N div 2,找到A就可以找到B

    为了程序更加效率,因为要找最大的,不妨贪心一下,咱们从大的开始downto下来。
    于是得到了最简单的程序。
    ###block code
    program ex;
    var n,num,i,ans:longint;
    begin
    read(n);
    for i:=(n div 2) downto 2 do
    begin
    if n mod i=0 then
    begin
    ans:=i;
    break;
    end;
    end;
    write(ans);
    end.

    • @ 2014-12-18 17:19:19

      例如 3*8=24,8不是素数,我们还需要分解,最后是2*3*2*2=28,一直到全素数,所有的因数无非是这些素因数的组合得到的,比如6是24的因数,无非是2*3得到的,无论哪个不是素数的因数,这个数的素因数的乘积肯定得到的。

      但是N=A*B已经是2个素数了,A B再怎么组合也只能乘出一个N,所以只有A,B2个因数,而且都是素因数。

  • 0
    @ 2014-12-14 18:25:40

    评测状态 Accepted
    题目 P1773 质因数
    递交时间 2014-12-14 18:24:24
    代码语言 Pascal
    评测机 上海红茶馆
    消耗时间 6 ms
    消耗内存 816 KiB
    评测时间 2014-12-14 18:24:25

    评测结果
    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 816 KiB, score = 10

    测试数据 #1: Accepted, time = 0 ms, mem = 816 KiB, score = 10

    测试数据 #2: Accepted, time = 0 ms, mem = 812 KiB, score = 10

    测试数据 #3: Accepted, time = 3 ms, mem = 816 KiB, score = 10

    测试数据 #4: Accepted, time = 3 ms, mem = 816 KiB, score = 10

    测试数据 #5: Accepted, time = 0 ms, mem = 816 KiB, score = 10

    测试数据 #6: Accepted, time = 0 ms, mem = 816 KiB, score = 10

    测试数据 #7: Accepted, time = 0 ms, mem = 816 KiB, score = 10

    测试数据 #8: Accepted, time = 0 ms, mem = 812 KiB, score = 10

    测试数据 #9: Accepted, time = 0 ms, mem = 816 KiB, score = 10

    Accepted, time = 6 ms, mem = 816 KiB, score = 100

    代码
    var q,n,p,i:longint;
    begin
    readln(n);
    for i:=2 to n div 2 do
    if n mod i=0 then
    begin
    q:=i;
    break;
    end;
    p:=n div q;
    writeln(p);
    end.

  • 0
    @ 2014-10-28 18:43:38

    弱弱AC
    var a,b,c,i:longint;
    begin
    read(a);
    for i:=2 to a do
    if a mod i=0 then begin
    b:=i;
    break;
    end;
    c:=a div b;
    writeln(c);
    end.

  • 0
    @ 2014-10-28 18:43:15

    var a,b,c,i:longint;
    begin
    read(a);
    for i:=2 to a do
    if a mod i=0 then begin
    b:=i;
    break;
    end;
    c:=a div b;
    writeln(c);
    end.

  • 0
    @ 2014-10-13 16:24:09

    因为数字为质因数乘积,所以除了本身和1只有两个因数,程序如下
    var n,i:longint;
    begin
    read(n);
    for i:=2 to trunc(sqrt(n)) do
    if n mod i=0 then begin write(n div i);halt;end;
    end.

信息

ID
1773
难度
3
分类
(无)
标签
(无)
递交数
2131
已通过
1042
通过率
49%
被复制
3
上传者