题解

69 条题解

  • -1
    @ 2017-10-15 15:26:51

    var
    n,i:longint;

    begin
    read(n);
    for i:=2 to n do
    if (n mod i=0) then
    begin
    write(n div i);
    exit;
    end;
    end.

  • -1
    @ 2017-07-08 14:58:43
    #include <cstdio>
    #include <iostream>
    
    
    using namespace std;
    
    int main(){
        int num;
        cin >> num;
        for (int i = 2; i < num / 2 + 1; i++){
            if (num % i == 0){
                cout << num / i << endl;
                break;
            }
        }
        return 0;
    }
    
  • -1
    @ 2016-11-09 21:18:14

    c++
    //#include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    inline int read()
    {
    char ch=getchar();
    int a=0,t=1;
    while(ch<'0'||ch>'9')
    {
    if(ch=='-') t=-1;
    ch=getchar();
    }
    while(ch<='9'&&ch>='0')
    {
    a=a*10+ch-'0';
    ch=getchar();
    }
    return a*t;
    }
    int main()
    {
    int n;
    //freopen("","r",stdin);freopen("","w",stdout);
    n=read();
    for(int i=2;i<=sqrt(n);++i)
    {
    if(n%i==0)
    {
    printf("%d",n/i);
    return 0;
    }
    }
    //fclose(stdin);fclose(stdout);
    return 0;
    }
    //

    如果一个数是两个质数乘积,那么一定不是两个非质数乘积

  • -1
    @ 2014-08-24 14:15:39

    #include<iostream>
    using namespace std;
    int pd(int n)
    {
    int i;
    if(n<=1)
    return 0;
    for(i=2;i*i<=n;i++)
    if(n%i==0)
    return n/i;
    }
    int main()
    {
    int n;
    cin>>n;
    cout<<pd(n)<<endl;
    return 0;
    }

  • -1
    @ 2013-11-20 22:54:39

    记录信息
    评测状态 Accepted
    题目 P1786 质因数分解
    递交时间 2013-11-20 22:52:46
    代码语言 C
    评测机 上海红茶馆
    消耗时间 0 ms
    消耗内存 540 KiB
    评测时间 2013-11-20 22:52:47

    评测结果
    编译成功

    foo.c: In function 'main':
    foo.c:9:1: warning: control reaches end of non-void function [-Wreturn-type]

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

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

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

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

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

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

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

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

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

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

    Accepted, time = 0 ms, mem = 540 KiB, score = 100

    代码
    #include <stdio.h>
    int main (){
    long n,i;
    scanf ("%ld",&n);
    for (i=2;i<n;i++)
    {if (n%i==0) {printf ("%ld\n",n/i);return 0;}
    }
    //若vijos给AC了,vijos是猪头.
    }
    用户信息
    lemontree712

    题目操作
    查看 P1786
    查看本题题解
    查看本题递交记录
    我的记录
    11-20 Accepted
    11-20 Accepted
    ​结论:……

    • @ 2014-04-23 17:17:10

      这个算法有证明的,如果是两个质数的乘积,就没有两个非质数乘积

  • -2
    @ 2017-04-26 18:36:33

    太简单了,无话可说,说白了就是分解因数,题意说了两个不同素数,直接分解即可
    #include<cstdio>
    #include<iostream>

    using namespace std;

    int main(){
    int n,i;
    scanf("%d",&n);//读取;
    for(i=2;i<n;i++)
    {
    if(n%i==0)//因数分解
    {
    printf("%d\n",n/i);//输出较大的
    break;//得到退出
    }
    }
    return 0;
    }

  • -2
    @ 2017-04-23 21:57:16
    var n,i:longint;
    begin
    read(n);
    for i:=2 to trunc(sqrt(n)) do
      if n mod i=0 then begin writeln(n div i);halt;end;
    end.
    
  • -2
    @ 2016-08-12 22:49:12

    只要找小的,再出一下就好啦~~~直接暴力!!!开始从大搜,60分+超时,从小的搜再i++就可以了~~~
    测试数据 #0: Accepted, time = 0 ms, mem = 560 KiB, score = 10

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

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

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

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

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

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

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

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

    测试数据 #9: Accepted, time = 0 ms, mem = 556 KiB, score = 10
    再来代码~~~
    #include<iostream>
    #include<cmath>
    using namespace std;
    bool pd(long int n)
    {
    if(n==0||n==1)
    return false;
    if(n==2)
    return true;
    for(long int i=2;i<=sqrt(n);i++)
    {
    if(n%i==0)
    return false;
    }
    return true;
    }
    int main()
    {
    long int n,mi;
    cin>>n;
    for(long int i=2;i<=sqrt(n);i++)
    {
    bool check=pd(i);
    if(check==true&&n%i==0)
    {
    mi=i;
    break;
    }
    }
    cout<<n/mi;
    return 0;
    }

  • -2
    @ 2016-05-15 19:24:57
    #include <stdio.h>
    #include <math.h>
    int main(){
        freopen("prime.in","r",stdin);
        freopen("prime.out","w",stdout);
        int n;
        scanf("%d", &n);
        for (int i=2;i<=sqrt(n);i++){
            if (!(n%i)) {
                n /= i;
                if (n>i){
                    printf("%d\n",n);
                    return 0;
                }   
                else{
                    printf("%d\n",i);
                    return 0;
                }    
            }
        }
    }
    

信息

ID
1786
难度
5
分类
搜索 | 搜索 | 枚举 点击显示
标签
递交数
5019
已通过
1922
通过率
38%
被复制
21
上传者