Cod sursa(job #342300)

Utilizator giuliastefGiulia Stef giuliastef Data 21 august 2009 11:56:45
Problema Numere 2 Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.15 kb
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
void imparte(int nr[], int b)
{
      int i, t = 0;
      for (i = nr[0]; i > 0; i--, t %= b)
              nr[i] = (t = t * 10 + nr[i]) / b;
      for (; nr[0] > 1 && !nr[nr[0]]; nr[0]--);
}
int rest(int nr[], int b)
{
      int i, t = 0;
      for (i = nr[0]; i > 0; i--)
              t = (t * 10 + (nr[i])) % b;
      return t;
}
int main()
{
    char p[101];
    int n[101],j,c,gasit;
    long int a,b,i;
    ifstream f ("numere2.in");
    ofstream g ("numere2.out");
    f.getline(p,101);
    i=2; gasit=0;
    a=1; b=1;
    while(!gasit)
    {
     if(b!=0)
     {
      c=strlen(p);
      for(j=0;j<c;j++)
       n[c-j]=(int)p[j] - 48;
      n[0]=c;   
     } 
     if(rest(n,i)==0)
     {
                       a=i; b=0;
                       while(rest(n,i)==0)
                       { imparte(n,i);
                          b++;
                       }
                       if(n[0]==1&&n[1]==1)
                        gasit=1;
     }
     i++;
    }
    g<<a<<"\n"<<b<<"\n";
    f.close();
    g.close();
    return 0;
}